|
| 1 | +--- |
| 2 | +- name: Update netbox definitions |
| 3 | + hosts: testbed-managers |
| 4 | + tasks: |
| 5 | + - name: Modify netbox resources for testbed-resource-nodes device_type |
| 6 | + ansible.builtin.replace: |
| 7 | + path: /opt/configuration/netbox/resources/200-rack-1000.yml |
| 8 | + after: '(?m)^ name: {{ item }}$' |
| 9 | + before: '^- ' |
| 10 | + regexp: '^ device_type: .*$' |
| 11 | + replace: ' device_type: Baremetal-Housing' |
| 12 | + loop: "{{ groups['testbed-resource-nodes'] }}" |
| 13 | + |
| 14 | + - name: Modify netbox resources for testbed-resource-nodes device_role |
| 15 | + ansible.builtin.replace: |
| 16 | + path: /opt/configuration/netbox/resources/200-rack-1000.yml |
| 17 | + after: '(?m)^ name: {{ item }}$' |
| 18 | + before: '^- ' |
| 19 | + regexp: '^ device_role: .*$' |
| 20 | + replace: ' device_role: Housing' |
| 21 | + loop: "{{ groups['testbed-resource-nodes'] }}" |
| 22 | + |
| 23 | + - name: Gather information about virtual baremetal devices created by tenks |
| 24 | + changed_when: false |
| 25 | + delegate_to: "{{ item }}" |
| 26 | + register: virtual_baremetal |
| 27 | + ansible.builtin.command: |
| 28 | + argv: |
| 29 | + - /home/dragon/tenks-venv/bin/vbmc |
| 30 | + - list |
| 31 | + - -f |
| 32 | + - json |
| 33 | + loop: "{{ groups['testbed-resource-nodes'] }}" |
| 34 | + |
| 35 | + - name: Gather information about virtual baremetal device interfaces created by tenks |
| 36 | + changed_when: false |
| 37 | + vars: |
| 38 | + nodes: "{{ virtual_baremetal.results | map(attribute='item') | list }}" |
| 39 | + vms: "{{ virtual_baremetal.results | map(attribute='stdout') | map('from_json') | list }}" |
| 40 | + delegate_to: "{{ item.0.key }}" |
| 41 | + become: true |
| 42 | + register: virtual_baremetal_interfaces |
| 43 | + ansible.builtin.command: |
| 44 | + argv: |
| 45 | + - /usr/bin/virsh |
| 46 | + - domiflist |
| 47 | + - "{{ item.1['Domain name'] }}" |
| 48 | + loop: "{{ dict(nodes | zip(vms)) | dict2items | subelements('value') }}" |
| 49 | + |
| 50 | + - name: Add netbox resources for virtualized baremetal nodes |
| 51 | + ansible.builtin.template: |
| 52 | + src: templates/baremetal-netbox-device.yml.j2 |
| 53 | + dest: "/opt/configuration/netbox/resources/400-rack-1000-{{ item.item.0.key }}-{{ item.item.1['Domain name']}}.yml" |
| 54 | + mode: 0644 |
| 55 | + owner: dragon |
| 56 | + group: dragon |
| 57 | + loop: "{{ virtual_baremetal_interfaces.results }}" |
0 commit comments