register not support variable

26 views
Skip to first unread message

Can Shen

unread,
Nov 15, 2014, 11:33:49 AM11/15/14
to ansible...@googlegroups.com, sc39...@qq.com
now . I  has run two comands  and register the  two variable , when I call the variable , the variable Unavailable (undefined)

flowing is my  playbook:

---
 - hosts: 127.0.0.1
   connection: local
   tasks:
    - name: test
      shell: df -{{ item.command }}
      register: "{{ item.res }}"
      with_items:
        - { command: h, res: cange }
        - { command: i, res: cange1 }

    - name: xxx1
      shell: echo "{{ cange.results[0].stdout }}" >/tmp/xxx

    - name: xxx2
      shell: echo "{{ cange1.results[0].stdout }}" >/tmp/xxx1

the error information:

TASK: [xxx1] ******************************************************************
fatal: [127.0.0.1] => One or more undefined variables: 'cange' is undefined

FATAL: all hosts have already failed -- aborting


Who can help me !   thank you  very much.

Matt Martz

unread,
Nov 15, 2014, 11:52:35 AM11/15/14
to ansible...@googlegroups.com, sc39...@qq.com
The value of register can not be a variable.  You must statically define it such as:

register: cange

Additionally, 'register' works a little differently with loops such as with_items.  See <http://docs.ansible.com/playbooks_loops.html#using-register-with-a-loop>

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/736a3855-7636-4220-98e7-9366e0211c04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages