I have the following which works. However, I would like to make the bash
script code "pretty". It is found under the "content" section of the
with_items. How can I do this?
- name: Ensure myscript.sh contains directory checks
blockinfile:
dest: "/home/{{ user.stdout }}/Scripts/myscript.sh"
insertafter: "{{ item.regexp }}"
marker: "## {mark} added by Ansible - {{ item.define }}"
content: "{{ item.content }}"
with_items:
- { regexp: "^trap.*exit\ 1.*1\ 2\ 3\ .*", define: "Check for /interface", content: "if [ -f /interface/ ]; then echo 'The /interface/$NATU directory is missing, aborting!'; exit 1; fi" }
- { regexp: "^NATU.*interface.*grep\ natu.*", define: "Check for /interface/natu", content: "if [ -f /interface/$NATU ]; then echo 'The /interface/$NATU directory is missing, aborting!'; exit 1; fi" }
I
want to have the content injected into the file as follows (which can
easily be done without a loop, but I wish to do this within the loop):
if [ -f /interface/ ]; then
echo 'The /interface/$NATU directory is missing, aborting!'
exit 1
fi
Thanks in advance!