Thank you Mohan that worked for me, but may I know why we need to place
them in double quotes??

On Tue, Nov 13, 2018, 11:56 AM Mohan L <[email protected] wrote:

>
>
> You have to quote the dictionary key as well.
>
> FROM
>
> - { src_tar: '/home/virtual/xx/sample.tar.gz', dest_tar: '/tmp/sss/' }
>
> TO
>
> - { 'src_tar': '/home/virtual/xx/sample.tar.gz', 'dest_tar': '/tmp/sss/' }
>
>
> Here is the working example. If you write a role and call that role from
> playbook then you no need to use var_files section. vars/main.yml is one of
> the default ansible search path.
>
> See how my tasks/main.yml :
>
> # cat roles/xyz/tasks/main.yml
>
> ---
>
> # tasks file for xyz
>
> - name: Extract /tmp/xx/sample.tar.gz into /tmp/sss
>
>   unarchive:
>
>     src: "{{ item.src_path }}"
>
>     dest: "{{ item.dest_path }}"
>
>   with_items: "{{ TAR }}"
>
>
>
> #See the vars/main.yml
>
> # cat roles/xyz/vars/main.yml
>
> ---
>
> # vars file for xyz
>
> TAR:
>
>  - { "src_path": "/tmp/xx/sample.tar.gz", "dest_path": "/tmp/sss/" }
>
>
>
> # See the Ansible playbook
>
> # cat /etc/asnible/site.yml
>
> ---
>
> - hosts: all
>
>
>
>   roles:
>
>     - xyz
>
>
> # ansible-playbook site.yml
>
>
> TASK [xyz : Extract /tmp/xx/sample.tar.gz into /tmp/sss]
> *******************************************
>
> ok: [localhost] => (item={u'src_path': u'/tmp/xx/sample.tar.gz',
> u'dest_path': u'/tmp/sss/'})
>
>
> PLAY RECAP
> *****************************************************************************************
>
> localhost                  : ok=2    changed=0    unreachable=0
> failed=0
>
>
> # ls /tmp/xx/sample.tar.gz
>
> /tmp/xx/sample.tar.gz
>
>
> # ls /tmp/sss/
>
> sample
>
>
>
>
> On Monday, November 12, 2018 at 11:09:08 PM UTC+5:30,
> [email protected] wrote:
>>
>> Hi Team,
>>
>> I am trying to unarchive a file is failing with below errors. Could
>> someone please look into it.
>>
>> *Playbook:*
>>
>> ---
>>
>> - hosts: all
>>
>>   vars_files:
>>
>>       - /etc/ansible/xx/xyz/vars/main.yml
>>
>>   tasks:
>>
>>   - name: test
>>
>>     unarchive:
>>
>>       src: "{{ item.src_tar }}"
>>
>>       dest: “{{ item.dest_tar }}”
>>
>>     with_items: "{{ TAR }}"
>>
>>
>> *vars_files:*
>>
>>
>> TAR:
>>
>> - { src_tar: '/home/virtual/xx/sample.tar.gz', dest_tar: '/tmp/sss/' }
>>
>>
>> *Error:*
>>
>> "msg": "The task includes an option with an undefined variable. The error
>> was: 'dict object' has no attribute 'dest_tar'\n\nThe error appears to have
>> been in '/etc/ansible/xx/xyz/tasks/main.yml': line 23, column 5, but
>> may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe
>> offending line appears to be:\n\n    with_items: \"{{ TAR }}\"\n  - name:
>> test\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/95a45bc1-676f-496b-8e03-709c10a845eb%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/95a45bc1-676f-496b-8e03-709c10a845eb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAEME5dSfRMCYMmF8uuuuL8SMSCxaq_cFibSoPdFLoYQU9w3X%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to