1

I have ansbile inv

# cat inv
[all]
vm1
vm2

I want to extract them in a comma delimited list using Jinja template

so I add jinja template

# cat comb_list.j2

{{ groups['all'] | map('extract', hostvars, ['item']) | join(',') }}"

but I guess item is not a hostvars, so throws error

I want end file to look like this

# cat comb_list
vm1,vm2
Sollosa
  • 1,887
  • 4
  • 19
  • 32

1 Answers1

1

The template

shell> cat comb_list.j2
{{ groups.all|join(',') }}

and the playbook

shell> cat playbook.yml
- hosts: all
  gather_facts: false
  tasks:
    - template:
        src: comb_list.j2
        dest: comb_list
      delegate_to: localhost
      run_once: true

gives

shell> ansible-playbook -i inv playbook.yml
...

shell> cat comb_list
vm1,vm2
Vladimir Botka
  • 2,108
  • 10
  • 14