Reputation: 613
I am trying to add a block in a file with space in front of it. Ansible script i used is given below.
- name: Disable Apache Directory listing, Symbolic Links, Server side includes and CGI execution
blockinfile:
dest: /etc/apache2/sites-enabled/000-default.conf
insertbefore: '</VirtualHost>'
block: |
Options -Indexes -FollowSymLinks -Includes -ExecCGI
LimitRequestBody 10485760
But output i am getting is given below :
<VirtualHost *:80>
# BEGIN ANSIBLE MANAGED BLOCK
Options -Indexes -FollowSymLinks -Includes -ExecCGI
LimitRequestBody 10485760
# END ANSIBLE MANAGED BLOCK
</VirtualHost>
What i am expecting is :
<VirtualHost *:80>
# BEGIN ANSIBLE MANAGED BLOCK
Options -Indexes -FollowSymLinks -Includes -ExecCGI
LimitRequestBody 10485760
# END ANSIBLE MANAGED BLOCK
</VirtualHost>
We can't use space in front of blockinfile code like we use in line
line: ' Options -Indexes -FollowSymLinks -Includes -ExecCGI'
How can we do it any ideas ?
Upvotes: 0
Views: 1785
Reputation: 996
Use yaml Block Indentation Indicator:
- name: Disable Apache Directory listing, Symbolic Links, Server side includes and CGI execution
blockinfile:
dest: testfile.conf
insertbefore: '</VirtualHost>'
block: |4
Options -Indexes -FollowSymLinks -Includes -ExecCGI
LimitRequestBody 10485760
This will give:
<VirtualHost *:80>
# BEGIN ANSIBLE MANAGED BLOCK
Options -Indexes -FollowSymLinks -Includes -ExecCGI
LimitRequestBody 10485760
# END ANSIBLE MANAGED BLOCK
</VirtualHost>
Note that the indentation in the block is important for this to work correctly.
https://yaml.org/spec/1.2/spec.html#id2793979
Upvotes: 1