1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- ---
- - hosts: localhost
- connection: local
- gather_facts: false
- tasks:
- - name: Read dhcp file
- set_fact:
- var: "{{ lookup('file', '/var/lib/dhcpd/dhcpd.leases').split()| unique | select| list }}"
- - name: Filter the ip
- set_fact:
- vars_new: "{{ var| ipv4('address')| to_nice_yaml}}"
- - name: Create the static ip
- shell: awk -F',' 'NR >1{print $3}' omnia/control_plane/roles/provision_cobbler/files/new_mapping_file.csv > static_hosts.yml
- changed_when: false
- ignore_errors: true
- - name: Create the dynamic inventory
- shell: |
- echo "[all]" > omnia/control_plane/roles/inventory/files/provisioned_hosts.yml
- echo "{{ vars_new }}" > temp.txt
- egrep -o '[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' temp.txt >>dynamic_hosts.yml
- changed_when: false
- ignore_errors: true
- - name: Final inventory
- shell: cat dynamic_hosts.yml static_hosts.yml| sort -ur >> omnia/control_plane/roles/inventory/files/provisioned_hosts.yml
- changed_when: false
|