Whitespace in Value for INI_FILE

68 views
Skip to first unread message

Tim Jabaut

unread,
May 18, 2015, 2:32:53 PM5/18/15
to ansible...@googlegroups.com
I have a problem when using the ini_file module as follows:

---
- name: Test 'ini_file'
  hosts: mediaserver
  user: root
  tasks:
  
  - name: Create 'config.ini' to include necessary values
    ini_file:
      dest=/root/testconfig.ini
      section={{ item.section }}
      option={{ item.option }}
      value={{ item.value }}
    with_items:
      - { section: 'General', option: 'test1', value: 'value2' }
      - { section: 'General2', option: 'test2', value: 2 }
      - { section: 'General3', option: 'test3', value: 'This is a test' }

Will produce the following results:

root@ansibleControl:~# ansible-playbook test.yml

PLAY [Test 'ini_file'] ********************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.154.243]

TASK: [Create 'config.ini' to include necessary values] ***********************
changed: [192.168.154.243] => (item={'section': 'General', 'option': 'test1', 'value': 'value2'})
changed: [192.168.154.243] => (item={'section': 'General2', 'option': 'test2', 'value': 2})
failed: [192.168.154.243] => (item={'section': 'General3', 'option': 'test3', 'value': 'This is a test'}) => {"failed": true, "item": {"option": "test3", "section": "General3", "value": "This is a test"}}
msg: this module requires key=value arguments (['dest=/root/testconfig.ini', 'section=General3', 'option=test3', 'value=This', 'is', 'a', 'test'])

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/test.retry

192.168.154.243            : ok=1    changed=0    unreachable=0    failed=1


It appears that the 'value', even though it is wrapped in quotes, is being treated as a list.

I am wondering if this is a bug.

Dan Vaida

unread,
Nov 28, 2015, 4:54:53 AM11/28/15
to Ansible Project
Try this:
 - name: Create 'config.ini' to include necessary values
    ini_file: >
      dest=./testconfig.ini
      section="{{ item.section }}"
      option="{{ item.option }}"
      value="{{ item.value }}"
    with_items:
      - { section: 'General', option: 'test1', value: 'value2' }
      - { section: 'General2', option: 'test2', value: 2 }
      - { section: 'General3', option: 'test3', value: 'This is a test' }
Reply all
Reply to author
Forward
0 new messages