Loading variables into plabook tasks failing

18 views
Skip to first unread message

abdul sattar Shaikh

unread,
Nov 4, 2017, 3:40:38 PM11/4/17
to Ansible Project
Hi All,

I am having below playbooks, I intent to include variables and I have got below message as "OK" and "changed" but file not copied over.

please review and advise.

Main playbook:
cat fetchfile.yml
---
  - hosts: all
    tasks:
      - name: Include vars of vars.yml into the 'dest' variable.
        include_vars:
          file: vars.yml
          name: dest
      - fetch:
          src: /tmp/xyz.txt
          dest: "{{ dest }}/"
          flat: yes

------------ variable playbook:
cat variable.yml
dest: /u01/app

SSH password:

PLAY [all] ******************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************
ok: [myserver]

TASK [Include vars of variable.yml into the 'dest' variable.] ************************************************************************************************************************************
ok: [myserver]

TASK [fetch] *********************************************************************************************************************************************************************************
changed: [myserver]

PLAY RECAP ***********************************************************************************************************************************************************************************
myserver                : ok=3    changed=1    unreachable=0    failed=0


------------------ it shows above as changed but when I am checking xyz.txt file at "dest" location, I could not see it, please advise.

Thank you.
Abdul

Kai Stian Olstad

unread,
Nov 4, 2017, 3:58:26 PM11/4/17
to ansible...@googlegroups.com
On 04. nov. 2017 20:40, abdul sattar Shaikh wrote:
> I am having below playbooks, I intent to include variables and I have got
> below message as "OK" and "changed" but file not copied over.
>
> please review and advise.
>
> Main playbook:
> cat fetchfile.yml
> ---
> - hosts: all
> tasks:
> - name: Include vars of vars.yml into the 'dest' variable.
> include_vars:
> file: vars.yml
> name: dest
> - fetch:
> src: /tmp/xyz.txt
> dest: "{{ dest }}/"
> flat: yes
>
> ------------ variable playbook:
> cat variable.yml
> dest: /u01/app
>

<snip />

>
> ------------------ it shows above as changed but when I am checking xyz.txt
> file at "dest" location, I could not see it, please advise.

You are looking at the wrong destination.
Look in the directory you run ansible-playbook, you will find a directory starting with {
If you run ansible-playbook with -vvv you'll see what I mean.

The name on the include_vars means, put the content in the file under the variable dest, so you dest is actually:
dest:
dest: /u01/app

It you add
- debug: var=dest
after include_vars you will also see that.


--
Kai Stian Olstad

abdul sattar Shaikh

unread,
Nov 5, 2017, 2:35:03 AM11/5/17
to Ansible Project
Hi Kai,

Thank you for quick response, will try advised and update you.

Thanks,
Abdul

abdul sattar Shaikh

unread,
Nov 5, 2017, 3:02:35 AM11/5/17
to Ansible Project
Hi Kai,

Yes, I can see the directory starting with {u'dest': u'  and in this directory i could see xyz.txt file, exact patch is as :  {u'dest': u'/u01/app/xyz.txt

Since I wish to put this file at /u01/app ( destination folder specified in variables.yml) and my main playbook which is fetchfile.yml is not doing it, please suggest where I am doing wrong in here.

Thank you.
Abdul

On Sunday, November 5, 2017 at 1:28:26 AM UTC+5:30, Kai Stian Olstad wrote:

abdul sattar Shaikh

unread,
Nov 5, 2017, 4:10:50 AM11/5/17
to Ansible Project
Hi Kai,

it is working for me now, I have removed  name: dest . 

Thank you so much for advise, have a nice day.

Thank you.
Abdul
Reply all
Reply to author
Forward
0 new messages