ansible-role-blockinfile
ansible-role-blockinfile copied to clipboard
Spacing in blocks does not work as expected
- name: Add logstash-forwarder to datadog process monitoring
blockinfile:
dest: /etc/dd-agent/conf.d/process.yaml
block: |
- name: logstash-forwarder
search_string: ['logstash-forwarder']
exact_match: false
thresholds:
# critical if no server.py is running
critical: [1, 1]
this code for example will be aligned to the first line in the block. this means that the result in the yaml would be:
- name: logstash-forwarder
search_string: ['logstash-forwarder']
notice that spacing. the - name
is at the beginning of the line and search_string
is two spaces behind.
This breaks the yaml format and should be handled.
http://pastie.org/10450801 with correct spaces
You might want to use Block Indentation Indicator in YAML.
- name: Add logstash-forwarder to datadog process monitoring
blockinfile:
dest: /etc/dd-agent/conf.d/process.yaml
block: |2
- name: logstash-forwarder
search_string: ['logstash-forwarder']
...
Notice that the block content has indentation with 4 spaces. You can get 2 space indented block from this task.
@yaegashi that is exactly what I want, but ansible 2.0.2 complains about the
block: |2
It's fine if I remove the number 2.
Still broken in ansible 2.1.1.0, that is the number in the block: | causes a syntax error.
It really does seem like the Block Indentation Indicator should work. I was not having any luck with it either unfortunately. It worked with one space, but anything else threw an error. I have resorted to putting the YAML all on one line:
- name: Add logstash-forwarder to datadog process monitoring
blockinfile:
dest: /etc/dd-agent/conf.d/process.yaml
block: " - name: logstash-forwarder\n search_string: ['logstash-forwarder']"
Any news on this issue? I'm still having the same problem as of Ansible 2.2.1.0.
Bug still open...
Also any number after block: |
except 2 throws an invalid syntax in the block itself.
The number after the |
describes how many lines the block is intended.
For example:
block: |2
insert some stuff
^^ to spaces here.
block: |4
insert some stuff
^^ 4 spaces here.
If you like to intend your line in the destination file you can use this workaround:
block: |
# this is a comment
insert some stuff
In this example, the line # this is a comment
is without intend and the line insert some stuff
has 2 leading spaces.
It is still broken in 2.11.5. Block Indentation Indicator is not working, but causes:
Syntax Error while loading YAML.
expected <block end>, but found '<scalar>'
For me, this works fone, but seems that I can only specify numbers until 1 digit, (and I need 12 spaces)