Invoke variable in ansible

24 Views Asked by At

I have a playbook defined as like below:

- name: Performing deployment tasks for UI cluster1
  include_tasks: deployment_tasks.yml
  when:
    - 'deploy_host_group == ui_cluster1'

And the deployment_tasks.yml declared as

- debug:
    msg: "{{deploy_host_group['app_profile']}}"

and the playbook vars declared as:

---
# vars file for deployment_role
deploy_host_group: ui_cluster1

#env based var declaration for deployment_role
ui_cluster1:
  app_profile: Hello,world,message

When I try to run the playbook it gives me an output as:

fatal: [localhost]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'app_profile'. 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'app_profile'\n\nThe error appears to be in '/test/roles/deprole/tasks/test.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- debug:\n  ^ here\n"

How can we actually invoke the variable deploy_host_group and get the array output defined in the variable ui_cluster1.

expected output is to print the below: "Hello,world,message"

0

There are 0 best solutions below