Transform a list of items to lines with an ansible filter

Viewed 32

Are there any ansible filter to transform a list of items to lines.

  "msg": [
        "barman receive-wal --stop srv1",
        "barman receive-wal --stop srv2",
        "barman receive-wal --stop srv3",
        "barman receive-wal --stop srv4",
        "barman receive-wal --stop srv5"
    ]

to:

 barman receive-wal --stop srv1
 barman receive-wal --stop srv2
 barman receive-wal --stop srv3
 barman receive-wal --stop srv4
 barman receive-wal --stop srv5
1 Answers

For example

    - copy:
        dest: test.txt
        content: "{{ l1|join('\n') }}"
      vars:
        l1: [
            "barman receive-wal --stop srv1",
            "barman receive-wal --stop srv2",
            "barman receive-wal --stop srv3",
            "barman receive-wal --stop srv4",
            "barman receive-wal --stop srv5"]

gives

shell> cat test.txt 
barman receive-wal --stop srv1
barman receive-wal --stop srv2
barman receive-wal --stop srv3
barman receive-wal --stop srv4
barman receive-wal --stop srv5
Related