template - line break of bash script is skipped

8 views
Skip to first unread message

dulh...@mailbox.org

unread,
Jan 30, 2023, 5:46:35 AM1/30/23
to ansible...@googlegroups.com
I am using the template module for a bash script


There is a problem with these lines

cd $PGARCH
{% raw %}while mapfile -t -n 20 ARCHIVE_LOGS && ((${#ARCHIVE_LOGS[@]})){% endraw %}
do

they should be like below

cd $PGARCH
while mapfile -t -n 20 ARCHIVE_LOGS && ((${#ARCHIVE_LOGS[@]}))
do

but factually the line break does not survive, hence the while loop, does not work

cd $PGARCH
while mapfile -t -n 20 ARCHIVE_LOGS && ((${#ARCHIVE_LOGS[@]}))do



I tried the change the .j2 to

cd $PGARCH
{% raw %}while mapfile -t -n 20 ARCHIVE_LOGS && ((${#ARCHIVE_LOGS[@]})){% endraw %}\n
do

this prevent the line breack from disappearing but the '\n' remains in the target file on the remote

how would I approach this?

Todd Lewis

unread,
Jan 30, 2023, 6:15:13 AM1/30/23
to ansible...@googlegroups.com, uto...@gmail.com
This works:
    cd $PGARCH
    {% raw -%}

    while mapfile -t -n 20 ARCHIVE_LOGS && ((${#ARCHIVE_LOGS[@]}))
    {% endraw %}
    do

    Or, if you had other Jinja variables to expand in that line, you
    could rewrite 
  ${#ARCHIVE_LOGS[@]}
as
  ${{ '{#' }}ARCHIVE_LOGS[@]}
-- 
Todd

dulh...@mailbox.org

unread,
Jan 30, 2023, 8:42:31 AM1/30/23
to ansible...@googlegroups.com
spot on, thanks.
 
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/14708166-5f98-17ce-8112-3c0ad6ad19ab%40gmail.com.
Reply all
Reply to author
Forward
0 new messages