summaryrefslogtreecommitdiffstats
path: root/roles/static_inventory/tasks
diff options
context:
space:
mode:
authorBogdan Dobrelya <bdobreli@redhat.com>2017-07-17 14:05:42 +0200
committerTomas Sedovic <tomas@sedovic.cz>2017-07-17 14:05:42 +0200
commita0d2dd9d29e8622e739870baf172f2b8a7e9c6a0 (patch)
treeaf6498151b459ab00685dd4f47b0286f2f90e9a8 /roles/static_inventory/tasks
parentbef7807177915fe4861fcef5c4a78884f49b3b0e (diff)
downloadopenshift-a0d2dd9d29e8622e739870baf172f2b8a7e9c6a0.tar.gz
openshift-a0d2dd9d29e8622e739870baf172f2b8a7e9c6a0.tar.bz2
openshift-a0d2dd9d29e8622e739870baf172f2b8a7e9c6a0.tar.xz
openshift-a0d2dd9d29e8622e739870baf172f2b8a7e9c6a0.zip
Add a role to generate a static inventory (#540)
* Add the static-inventory role that configures the inventory/hosts file by the given path, or creates it for you. Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
Diffstat (limited to 'roles/static_inventory/tasks')
-rw-r--r--roles/static_inventory/tasks/checkpoint.yml17
-rw-r--r--roles/static_inventory/tasks/main.yml6
-rw-r--r--roles/static_inventory/tasks/openstack.yml47
3 files changed, 70 insertions, 0 deletions
diff --git a/roles/static_inventory/tasks/checkpoint.yml b/roles/static_inventory/tasks/checkpoint.yml
new file mode 100644
index 000000000..c0365bd3d
--- /dev/null
+++ b/roles/static_inventory/tasks/checkpoint.yml
@@ -0,0 +1,17 @@
+---
+- name: check for static inventory dir
+ stat:
+ path: "{{ inventory_path }}"
+ register: stat_inventory_path
+
+- name: create static inventory dir
+ file:
+ path: "{{ inventory_path }}"
+ state: directory
+ mode: 0750
+ when: not stat_inventory_path.stat.exists
+
+- name: create inventory from template
+ template:
+ src: inventory.j2
+ dest: "{{ inventory_path }}/hosts"
diff --git a/roles/static_inventory/tasks/main.yml b/roles/static_inventory/tasks/main.yml
new file mode 100644
index 000000000..15c81690e
--- /dev/null
+++ b/roles/static_inventory/tasks/main.yml
@@ -0,0 +1,6 @@
+---
+- name: Generate in-memory inventory
+ include: openstack.yml
+
+- name: Checkpoint in-memory data into a static inventory
+ include: checkpoint.yml
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 }}'