Problem with ansible variables

90 views
Skip to first unread message

Adrian Paraschiv

unread,
Jan 12, 2015, 2:36:51 AM1/12/15
to ansible...@googlegroups.com
Hello,

I have this small playbook and t doesn't convert veriables:
---
- hosts: karma
  user: root
  sudo: True
  tasks:
    - shell: ls /images/KBU/ | grep MODULE | awk -F- '{print $4}' | awk -F. '{print $1}' | tail -1
      register: MODULE
      environment:
        MODULE: "{{ MODULE }}"
    - shell: echo "{{ MODULE }}"
----------------------------
at TASK: [shell echo "{{ MODULE_GOROCO }}"] **************************************

it failes, it echoes the hole stdout of ansible:
------------------
cmd:
echo "{u'changed': True, u'end': u'2015-01-12 08:30:33.137879', u'stdout': u'G10R00C00', u'cmd': u"ls /images/KBU/ | grep KBUONE | awk -F- '{print $4}' | awk -F. '{print $1}' | tail -1", u'rc': 0, u'start': u'2015-01-12 08:30:33.121037', u'stderr': u'', u'delta': u'0:00:00.016842', 'invocation': {'module_name': u'shell', 'module_args': u"ls /images/KBU/ | grep KBUONE | awk -F- '{print $4}' | awk -F. '{print $1}' | tail -1"}, 'stdout_lines': [u'G10R00C00'], u'warnings': []}"
stderr: tail: option used in invalid context -- 1
tail: option used in invalid context -- 1
-----------------
it should echo this: G10R00C00. How do I echo the content of a registered variable ?


Brian Coca

unread,
Jan 13, 2015, 8:54:01 AM1/13/15
to ansible...@googlegroups.com
it is substituting but I'm guessing more than you want.

try:

environment:
MODULE: "{{MODULE.stdout}}"

also "shell: echo" will not display any output to your screen, you
might want to register it and use debug module to display.


--
Brian Coca

Adrian Paraschiv

unread,
Jan 16, 2015, 7:05:21 AM1/16/15
to ansible...@googlegroups.com
Thanks Brian,

It worked!


Reply all
Reply to author
Forward
0 new messages