Reputation: 7776
I am trying to concatenate variable to itself in an Ansible playback loop, but I am unable to do it. Might be its simple but unable to achieve this.
What I am trying here.
- name: all directories
set_fact: all_dir={{ item }}
with_items:
- src/main/java
- src/main/test
- src/main/resources
- debug: var=all_dir
Expected Output in all_dir
src/main/java src/main/test src/main/resources
I tried join . Any suggestion?
Upvotes: 2
Views: 4266
Reputation: 60059
join
is what you should be using.
- hosts: 127.0.0.1
connection: local
vars:
dirs:
- src/main/java
- src/main/test
- src/main/resources
all_dir: "{{ dirs | join(' ') }}"
tasks:
- debug: var=all_dir
Or via set_fact
:
- hosts: 127.0.0.1
connection: local
vars:
dirs:
- src/main/java
- src/main/test
- src/main/resources
tasks:
- set_fact:
all_dir: "{{ dirs | join(' ') }}"
- debug: var=all_dir
TASK: [debug var=all_dir] *****************************************************
ok: [127.0.0.1] => {
"var": {
"all_dir": "src/main/java src/main/test src/main/resources"
}
}
Upvotes: 5