bookworm/create_inventory.yml

22 lines
567 B
YAML
Raw Normal View History

2023-09-07 13:10:12 +02:00
- hosts: localhost
gather_facts: false
become: false
vars:
csv_hosts: "{{ out.stdout_lines|map('split', ';')|groupby('0') }}"
ini_hosts: |
{% for group in csv_hosts %}
[{{ group.0 }}]
{% for host in group.1|map(attribute='1') %}
{{ host }}
{% endfor %}
{% endfor %}
tasks:
- shell: scp linuxadmin@server:/etc/linuxmuster/sophomorix/default-school/devices.csv .
- shell: cat devices.csv | grep -v ^# | grep -v ^$
register: out
- copy:
dest: devices.ini
content: "{{ ini_hosts }}"