Skip to content

Instantly share code, notes, and snippets.

@riton
Last active November 29, 2016 13:07
Show Gist options
  • Save riton/176d2c6df31b9ca6757a02ce2f146c9c to your computer and use it in GitHub Desktop.
Save riton/176d2c6df31b9ca6757a02ce2f146c9c to your computer and use it in GitHub Desktop.
Ansible / BlockInFile / With_Items
- hosts: localhost
connection: local
gather_facts: false
become: false
tasks:
- blockinfile:
dest: '/tmp/THE_FILE'
block: |
foo {{ item }} bar
marker: "THE BLOCK MARKER FOR {{ item }}"
with_items:
- foo
- bar
- hello
- world
$ ansible --version
ansible 2.2.0.0

Error message is:

$ ansible-playbook /tmp/t.playbook 

PLAY [localhost] ***************************************************************

TASK [blockinfile] *************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'item' is undefined\n\nThe error appears to have been in '/tmp/t.playbook': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n    - blockinfile:\n      ^ here\n"}
        to retry, use: --limit @/tmp/t.retry

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment