Question:
In Ansible (1.9.4) or 2.0.0
I ran the following action:
1 2 |
- debug: msg="line1 \n {{ var2 }} \n line3 with var3 = {{ var3 }}" |
$ cat roles/setup_jenkins_slave/tasks/main.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
- debug: msg="Installing swarm slave = {{ slave_name }} at {{ slaves_dir }}/{{ slave_name }}" tags: - koba - debug: msg="1 == Slave properties = fsroot[ {{ slave_fsroot }} ], master[ {{ slave_master }} ], connectingToMasterAs[ {{ slave_user }} ], description[ {{ slave_desc }} ], No.Of.Executors[ {{ slave_execs }} ], LABELs[ {{ slave_labels }} ], mode[ {{ slave_mode }} ]" tags: - koba - debug: msg="print(2 == Slave properties = \n\nfsroot[ {{ slave_fsroot }} ],\n master[ {{ slave_master }} ],\n connectingToMasterAs[ {{ slave_user }} ],\n description[ {{ slave_desc }} ],\n No.Of.Executors[ {{ slave_execs }} ],\n LABELs[ {{ slave_labels }} ],\n mode[ {{ slave_mode }} ])" tags: - koba |
But this is not printing the variable with new lines (for the 3rd debug action)?
Answer:
As a workaround, I used with_items and it kind of worked for me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
- debug: msg="Installing swarm slave = {{ slave_name }} at {{ slaves_dir }}/{{ slave_name }}" - debug: msg="Slave properties = {{ item.prop }} [ {{ item.value }} ]" with_items: - { prop: 'fsroot', value: "{{ slave_fsroot }}" } - { prop: 'master', value: "{{ slave_master }}" } - { prop: 'connectingToMasterAs', value: "{{ slave_user }}" } - { prop: 'description', value: "{{ slave_desc }}" } - { prop: 'No.Of.Executors', value: "{{ slave_execs }}" } - { prop: 'LABELs', value: "{{ slave_labels }}" } - { prop: 'mode', value: "{{ slave_mode }}" } tags: - koba |