add static inventory generation
This commit is contained in:
parent
fe8064784e
commit
8cc63c3ad8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
collections/ansible_collections
|
||||
__old
|
||||
facts.d
|
||||
|
15
csv_static_inventory.yml
Normal file
15
csv_static_inventory.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: CSV Inventory Creation
|
||||
hosts: all
|
||||
become: no
|
||||
gather_facts: no
|
||||
|
||||
|
||||
vars_files:
|
||||
- vars/defaults.yml
|
||||
|
||||
|
||||
tasks:
|
||||
- import_tasks: tasks/generate_static_from_csv.yml
|
||||
|
||||
...
|
1002000
files/csv_static_inventory.ini
Normal file
1002000
files/csv_static_inventory.ini
Normal file
File diff suppressed because it is too large
Load Diff
15
tasks/generate_static_from_csv.yml
Normal file
15
tasks/generate_static_from_csv.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Read in CSV contents
|
||||
read_csv :
|
||||
path : "{{ playbook_dir }}/files/{{ __csv_file }}"
|
||||
register : r_csv_inventory
|
||||
delegate_to : localhost
|
||||
|
||||
|
||||
- name: Write inventory from CSV data
|
||||
template:
|
||||
src : templates/csv_static_inventory.j2
|
||||
dest : "{{ playbook_dir }}/files/csv_static_inventory.ini"
|
||||
|
||||
|
||||
...
|
9
templates/csv_static_inventory.j2
Normal file
9
templates/csv_static_inventory.j2
Normal file
@ -0,0 +1,9 @@
|
||||
{% for csv_group in r_csv_inventory.list %}
|
||||
[{{ csv_group.tower_group }}]
|
||||
{% for csv_host in r_csv_inventory.list %}
|
||||
{% if csv_host.tower_group == csv_group.tower_group %}
|
||||
{{ csv_host.inventory_name }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endfor %}
|
Loading…
x
Reference in New Issue
Block a user