summaryrefslogtreecommitdiffstats
path: root/roles/static_inventory/tasks/openstack.yml
diff options
context:
space:
mode:
Diffstat (limited to 'roles/static_inventory/tasks/openstack.yml')
-rw-r--r--roles/static_inventory/tasks/openstack.yml47
1 files changed, 47 insertions, 0 deletions
diff --git a/roles/static_inventory/tasks/openstack.yml b/roles/static_inventory/tasks/openstack.yml
new file mode 100644
index 000000000..a25502835
--- /dev/null
+++ b/roles/static_inventory/tasks/openstack.yml
@@ -0,0 +1,47 @@
+---
+- no_log: true
+ block:
+ - name: fetch all nodes from openstack shade dynamic inventory
+ command: shade-inventory --list
+ register: registered_nodes_output
+ when: refresh_inventory|bool
+
+ - name: set fact for openstack inventory cluster nodes
+ set_fact:
+ registered_nodes: "{{ (registered_nodes_output.stdout | from_json) | json_query(q) }}"
+ vars:
+ q: "[] | [?metadata.clusterid=='{{stack_name}}']"
+ when:
+ - refresh_inventory|bool
+
+ - name: set_fact for openstack inventory nodes
+ set_fact:
+ registered_nodes_floating: "{{ (registered_nodes_output.stdout | from_json) | json_query(q2) }}"
+ vars:
+ q: "[] | [?metadata.group=='infra.{{stack_name}}']"
+ q2: "[] | [?metadata.clusterid=='{{stack_name}}'] | [?public_v4!='']"
+ when:
+ - refresh_inventory|bool
+
+ - name: Add cluster nodes w/o floating IPs to inventory
+ with_items: "{{ registered_nodes }}"
+ when: not item in registered_nodes_floating
+ add_host:
+ name: '{{ item.name }}'
+ groups: '{{ item.metadata.group }}'
+ ansible_host: '{{ item.private_v4 }}'
+ ansible_fqdn: '{{ item.name }}'
+ ansible_private_key_file: '{{ private_ssh_key }}'
+ private_v4: '{{ item.private_v4 }}'
+
+ - name: Add cluster nodes with floating IPs to inventory
+ with_items: "{{ registered_nodes_floating }}"
+ when: item in registered_nodes_floating
+ add_host:
+ name: '{{ item.name }}'
+ groups: '{{ item.metadata.group }}'
+ ansible_host: '{{ item.public_v4 }}'
+ ansible_fqdn: '{{ item.name }}'
+ ansible_private_key_file: '{{ private_ssh_key }}'
+ private_v4: '{{ item.private_v4 }}'
+ public_v4: '{{ item.public_v4 }}'