Adding lines with variables

35 views
Skip to first unread message

John Oliver

unread,
Sep 9, 2014, 1:01:46 PM9/9/14
to ansible...@googlegroups.com
ansible 1.6.10


- name: Get vmail home directory
  shell: "/bin/grep vmail /etc/passwd | cut -d':' -f6"
  register: vmail_dir

- name: Modify postfix config
  lineinfile: dest=/etc/postfix/main.cf
              line="{{item}}"
              insertafter='^mydestination\ =\ \$myhostname,\ localhost\.\$mydomain,\ localhost$'
  with_items:
    - "virtual_mailbox_maps = ldap:/etc/postfix/ldap-users.cf"
    - "virtual_mailbox_base = {{vmail_dir}}"
    - "virtual_mailbox_domains = $mydomain"


This fails like::

failed: [test] => (item=virtual_mailbox_base = {u'changed': True, u'end': u'2014-09-09 09:38:11.112576', u'stdout': u'/home/vmail', u'cmd': u"/bin/grep vmail /etc/passwd | cut -d':' -f6", u'rc': 0, u'start': u'2014-09-09 09:38:11.109507', u'stderr': u'', u'delta': u'0:00:00.003069', 'invocation': {'module_name': 'shell', 'module_args': "/bin/grep vmail /etc/passwd | cut -d':' -f6"}, 'stdout_lines': [u'/home/vmail']}) => {"failed": true, "item": "virtual_mailbox_base = {u'changed': True, u'end': u'2014-09-09 09:38:11.112576', u'stdout': u'/home/vmail', u'cmd': u\"/bin/grep vmail /etc/passwd | cut -d':' -f6\", u'rc': 0, u'start': u'2014-09-09 09:38:11.109507', u'stderr': u'', u'delta': u'0:00:00.003069', 'invocation': {'module_name': 'shell', 'module_args': \"/bin/grep vmail /etc/passwd | cut -d':' -f6\"}, 'stdout_lines': [u'/home/vmail']}"}
msg: this module requires key=value arguments (['dest=/etc/postfix/main.cf', "line=virtual_mailbox_base = {u'changed': True, u'end': u'2014-09-09 09:38:11.112576', u'stdout': u'/home/vmail', u'cmd': u/bin/grep", 'vmail', '/etc/passwd', '|', 'cut', '-d:', "-f6, u'rc': 0, u'start': u'2014-09-09 09:38:11.109507', u'stderr': u'', u'delta': u'0:00:00.003069', 'invocation': {'module_name': 'shell', 'module_args': /bin/grep", 'vmail', '/etc/passwd', '|', 'cut', '-d:', "-f6}, 'stdout_lines': [u'/home/vmail']}", 'insertafter=^mydestination\\ =\\ \\$myhostname,\\ localhost\\.\\$mydomain,\\ localhost$'])


It looks like I'm just not getting the quoting right.  I tried enquoting the line with strong quotes and the variable with double quotes.

Shaunak Kashyap

unread,
Sep 9, 2014, 1:23:54 PM9/9/14
to ansible...@googlegroups.com
In the with_items list, instead of this:

"virtual_mailbox_base = {{vmail_dir}}"

Try changing it to this:

"virtual_mailbox_base = {{vmail_dir.stdout_lines[0]}}"

Shaunak


--
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/f843a54d-19e1-479b-8d39-afb65b6679ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
"Now the hardness of this world slowly grinds your dreams away / Makin' a fool's joke out of the promises we make" --- Bruce Springsteen, "Blood Brothers"
Reply all
Reply to author
Forward
0 new messages