sorry false alarm. my backup_archivelogs.sh file was completely off
I am trying to use template module to send 2 shell scripts to a remote.
### TASK ##################################################################################################
- name: configure postgres - template backup scripts
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ postgres_base }}/tools/backup/{{ item }}"
backup: yes
owner: postgres
group: postgres
mode: 0600
become: yes
loop:
- backup_postgres10.sh
- backup_archivelogs.sh
### TASK ##################################################################################################
while the first item is being templated out fine the second fails with a "Missing end of comment tag. String: #!/bin/bash" error. With 0 experience with jinja2 I can not make any sense of what I found in the documentation in that respect.
Content of both files it 100% original bash script content.
### backup_archivelogs.sh.j2 #############################################################################
#!/bin/bash
#
# $Header$
#
# backup postgres archivelogs to TSM
# source postgres env
source /opt/db/postgres/bin/.pg.env
#set -x
# write logs to backup
# do an incremental backup of the postgres archive/wal logs
# take a bunch of 20 logs per dsmc incr call
cd $PGARCH
while mapfile -t -n 20 ARCHIVE_LOGS && ((${#ARCHIVE_LOGS[@]}))
do
echo ">>> backing up: ${ARCHIVE_LOGS[@]}"
sudo /opt/tivoli/tsm/client/ba/bin/dsmc incr "${ARCHIVE_LOGS[@]}"
# check return code, if 0/true then purge logfile
RET=$?
if [ $RET -eq 0 ]; then
echo
echo ">>> TSM incremental backup successful, purging archive logs up to ${ARCHIVE_LOGS[-1]} <<<"
rm "${ARCHIVE_LOGS[@]}"
fi
sleep 2
done < <(ls -1 0*)
### OUTPUT ################################################################################################
TASK [configure postgres - template backup scripts] ********************************************************************
task path: /home/username/repos/ansible/open_source/postgres_create_service/postgres_create_service.yml:83
<server.intern> ESTABLISH SSH CONNECTION FOR USER: None
<server.intern> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' server.intern '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<server.intern> (0, b'/home/username\n', b'')
<server.intern> ESTABLISH SSH CONNECTION FOR USER: None
<server.intern> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' server.intern '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /var/tmp `"&& mkdir "` echo /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610 `" && echo ansible-tmp-1663162681.3683012-2675848-43258002595610="` echo /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610 `" ) && sleep 0'"'"''
<server.intern> (0, b'ansible-tmp-1663162681.3683012-2675848-43258002595610=/var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610\n', b'')
Using module file /usr/lib/python3.8/site-packages/ansible/modules/stat.py
<server.intern> PUT /home/username/.ansible/tmp/ansible-local-2675679n2q7xy3g/tmpwcgv_g_c TO /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_stat.py
<server.intern> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' '[server.intern]'
<server.intern> (0, b'sftp> put /home/username/.ansible/tmp/ansible-local-2675679n2q7xy3g/tmpwcgv_g_c /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_stat.py\n', b'')
<server.intern> ESTABLISH SSH CONNECTION FOR USER: None
<server.intern> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' server.intern '/bin/sh -c '"'"'setfacl -m u:postgres:r-x /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/ /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_stat.py && sleep 0'"'"''
<server.intern> (0, b'', b'')
<server.intern> ESTABLISH SSH CONNECTION FOR USER: None
<server.intern> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' -tt server.intern '/bin/sh -c '"'"'sudo -H -S -n -u postgres /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-ztbiuccpcrwstltpesmvsnlefldjhueu ; /usr/libexec/platform-python /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_stat.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<server.intern> (0, b'\r\n\r\n{"changed": false, "stat": {"exists": true, "path": "/opt/db/postgres/tools/backup/backup_postgres10.sh", "mode": "0600", "isdir": false, "ischr": false, "isblk": false, "isreg": true, "isfifo": false, "islnk": false, "issock": false, "uid": 1001, "gid": 1001, "size": 9567, "inode": 6553734, "dev": 64772, "nlink": 1, "atime": 1663162307.594887, "mtime": 1662108268.8151002, "ctime": 1662108269.4020917, "wusr": true, "rusr": true, "xusr": false, "wgrp": false, "rgrp": false, "xgrp": false, "woth": false, "roth": false, "xoth": false, "isuid": false, "isgid": false, "blocks": 24, "block_size": 4096, "device_type": 0, "readable": true, "writeable": true, "executable": false, "pw_name": "postgres", "gr_name": "postgres", "checksum": "c25840eb364bd104b796679eef8082ad6887bae3", "mimetype": "text/x-shellscript", "charset": "us-ascii", "version": "3998925608", "attributes": , "attr_flags": ""}, "invocation": {"module_args": {"path": "/opt/db/postgres/tools/ba
ck
up/backup_postgres10.sh", "follow": false, "get_checksum": true, "checksum_algorithm": "sha1", "get_md5": false, "get_mime": true, "get_attributes": true}}}\r\n', b'Shared connection to server.intern closed.\r\n')
Using module file /usr/lib/python3.8/site-packages/ansible/modules/file.py
<server.intern> PUT /home/username/.ansible/tmp/ansible-local-2675679n2q7xy3g/tmpafre2fjl TO /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_file.py
<server.intern> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' '[server.intern]'
<server.intern> (0, b'sftp> put /home/username/.ansible/tmp/ansible-local-2675679n2q7xy3g/tmpafre2fjl /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_file.py\n', b'')
<server.intern> ESTABLISH SSH CONNECTION FOR USER: None
<server.intern> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' server.intern '/bin/sh -c '"'"'setfacl -m u:postgres:r-x /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/ /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_file.py && sleep 0'"'"''
<server.intern> (0, b'', b'')
<server.intern> ESTABLISH SSH CONNECTION FOR USER: None
<server.intern> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/home/username/.ansible/cp/8ca9f05e1f"' -tt server.intern '/bin/sh -c '"'"'sudo -H -S -n -u postgres /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-qttckqlufxsixkcjmiiesbbvfedjlfuy ; /usr/libexec/platform-python /var/tmp/ansible-tmp-1663162681.3683012-2675848-43258002595610/AnsiballZ_file.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<server.intern> (0, b'\r\n{"path": "/opt/db/postgres/tools/backup/backup_postgres10.sh", "changed": false, "diff": {"before": {"path": "/opt/db/postgres/tools/backup/backup_postgres10.sh"}, "after": {"path": "/opt/db/postgres/tools/backup/backup_postgres10.sh"}}, "uid": 1001, "gid": 1001, "owner": "postgres", "group": "postgres", "mode": "0600", "state": "file", "secontext": "system_u:object_r:usr_t:s0", "size": 9567, "invocation": {"module_args": {"owner": "postgres", "group": "postgres", "mode": 384, "dest": "/opt/db/postgres/tools/backup/backup_postgres10.sh", "_original_basename": "backup_postgres10.sh.j2", "recurse": false, "state": "file", "path": "/opt/db/postgres/tools/backup/backup_postgres10.sh", "force": false, "follow": true, "modification_time_format": "%Y%m%d%H%M.%S", "access_time_format": "%Y%m%d%H%M.%S", "unsafe_writes": false, "_diff_peek": null, "src": null, "modification_time": null, "access_time": null, "seuser": null, "serole": null, "selevel": null, "setype":
nu