Adding lines with variables

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.

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