summaryrefslogtreecommitdiffstats
path: root/playbooks/openstack/sample-inventory
diff options
context:
space:
mode:
authorTomas Sedovic <tomas@sedovic.cz>2017-10-23 12:57:29 +0200
committerTomas Sedovic <tomas@sedovic.cz>2017-11-07 14:35:46 +1100
commit4ed9aef6f8ed0850e70b498e780d0d8e22bc277f (patch)
treea2c63b7379e46d2aca4379eccceaaf91ef92fc4f /playbooks/openstack/sample-inventory
parent8b8eeab919b76bee6a2e0ad1336bd4dbb1db1e95 (diff)
downloadopenshift-4ed9aef6f8ed0850e70b498e780d0d8e22bc277f.tar.gz
openshift-4ed9aef6f8ed0850e70b498e780d0d8e22bc277f.tar.bz2
openshift-4ed9aef6f8ed0850e70b498e780d0d8e22bc277f.tar.xz
openshift-4ed9aef6f8ed0850e70b498e780d0d8e22bc277f.zip
Add openshift_openstack role and move tasks there
All the tasks that were previously in playbooks are now under `roles/openshift_openstack`. The `openshift-cluster` directory now only contains playbooks that include tasks from that role. This makes the structure much closer to that of the AWS provider.
Diffstat (limited to 'playbooks/openstack/sample-inventory')
-rwxr-xr-xplaybooks/openstack/sample-inventory/inventory.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/playbooks/openstack/sample-inventory/inventory.py b/playbooks/openstack/sample-inventory/inventory.py
index 6a1b74b3d..47c56d94d 100755
--- a/playbooks/openstack/sample-inventory/inventory.py
+++ b/playbooks/openstack/sample-inventory/inventory.py
@@ -1,4 +1,11 @@
#!/usr/bin/env python
+"""
+This is an Ansible dynamic inventory for OpenStack.
+
+It requires your OpenStack credentials to be set in clouds.yaml or your shell
+environment.
+
+"""
from __future__ import print_function
@@ -7,7 +14,8 @@ import json
import shade
-if __name__ == '__main__':
+def build_inventory():
+ '''Build the dynamic inventory.'''
cloud = shade.openstack_cloud()
inventory = {}
@@ -39,13 +47,10 @@ if __name__ == '__main__':
dns = [server.name for server in cluster_hosts
if server.metadata['host-type'] == 'dns']
- lb = [server.name for server in cluster_hosts
- if server.metadata['host-type'] == 'lb']
+ load_balancers = [server.name for server in cluster_hosts
+ if server.metadata['host-type'] == 'lb']
- osev3 = list(set(nodes + etcd + lb))
-
- groups = [server.metadata.group for server in cluster_hosts
- if 'group' in server.metadata]
+ osev3 = list(set(nodes + etcd + load_balancers))
inventory['cluster_hosts'] = {'hosts': [s.name for s in cluster_hosts]}
inventory['OSEv3'] = {'hosts': osev3}
@@ -55,7 +60,7 @@ if __name__ == '__main__':
inventory['infra_hosts'] = {'hosts': infra_hosts}
inventory['app'] = {'hosts': app}
inventory['dns'] = {'hosts': dns}
- inventory['lb'] = {'hosts': lb}
+ inventory['lb'] = {'hosts': load_balancers}
for server in cluster_hosts:
if 'group' in server.metadata:
@@ -68,21 +73,24 @@ if __name__ == '__main__':
for server in cluster_hosts:
ssh_ip_address = server.public_v4 or server.private_v4
- vars = {
+ hostvars = {
'ansible_host': ssh_ip_address
}
public_v4 = server.public_v4 or server.private_v4
if public_v4:
- vars['public_v4'] = public_v4
+ hostvars['public_v4'] = public_v4
# TODO(shadower): what about multiple networks?
if server.private_v4:
- vars['private_v4'] = server.private_v4
+ hostvars['private_v4'] = server.private_v4
node_labels = server.metadata.get('node_labels')
if node_labels:
- vars['openshift_node_labels'] = node_labels
+ hostvars['openshift_node_labels'] = node_labels
+
+ inventory['_meta']['hostvars'][server.name] = hostvars
+ return inventory
- inventory['_meta']['hostvars'][server.name] = vars
- print(json.dumps(inventory, indent=4, sort_keys=True))
+if __name__ == '__main__':
+ print(json.dumps(build_inventory(), indent=4, sort_keys=True))