The group_vars directory contains files *for each hostgroup* defined in 
your inventory file. The files define variables that member hosts can use. 
So in your case the file should be group_vars/docker_con.yml

On Sunday, September 30, 2018 at 6:19:02 PM UTC-5, Atul Sharma wrote:
>
> group_vars/vars.yml 
>
> [root@master mywork]# cat  group_vars/vars
> ---
> MyVariable:
>   var1: 'hello'
>   var2: 'world'
>
>
>
> inventory file:
> [mylocal]
> localhost
>
> [docker_con]
> con1
> con2
>
>
> [ofsaavar:children]
> mylocal
> docker_con
>
> [ofsaavar:vars]
> ansible_host=con1
> ansible_host=con2
> ansible_ssh_user=root
>
>
>
>
> to access group_vars dictionary key is not working . please check the 
> following playbook
>
> test.yml 
>
> ---
> - hosts: docker_con
>   remote_user: root
>   gather_facts: False
>
>   tasks:
>     - debug:
>          msg: "{{MyVariable.var1}}"
>
>
>
> error:
>
> task path: /root/mywork/stat.yml:9
> fatal: [con1]: FAILED! => {
>     "msg": "The task includes an option with an undefined variable. The 
> error was: 'MyVariable' is undefined\n\nThe error appears to have been in 
> '/root/mywork/stat.yml': line 9, column 7, but may\nbe elsewhere in the 
> file depending on the exact syntax problem.\n\nThe offending line appears 
> to be:\n\n  tasks:\n    - debug:\n      ^ here\n"
> }
> fatal: [con2]: FAILED! => {
>     "msg": "The task includes an option with an undefined variable. The 
> error was: 'MyVariable' is undefined\n\nThe error appears to have been in 
> '/root/mywork/stat.yml': line 9, column 7, but may\nbe elsewhere in the 
> file depending on the exact syntax problem.\n\nThe offending line appears 
> to be:\n\n  tasks:\n    - debug:\n      ^ here\n"
> }
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d59cf869-2603-461b-b71d-2e4516ba20d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to