From dbcee4041a50b4868436c9682f70a6d240ff5b1e Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 15 May 2018 22:10:36 +0100 Subject: [PATCH] tests: refactor gcloud.py to be dynamic inventory. --- tests/ansible/ansible.cfg | 2 +- .../inventory/gcloud.py} | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) rename tests/ansible/{gcloud-ansible-playbook.py => lib/inventory/gcloud.py} (72%) diff --git a/tests/ansible/ansible.cfg b/tests/ansible/ansible.cfg index 8c9f66e0..437e67b7 100644 --- a/tests/ansible/ansible.cfg +++ b/tests/ansible/ansible.cfg @@ -1,5 +1,5 @@ [defaults] -inventory = hosts +inventory = hosts,lib/inventory gathering = explicit strategy_plugins = ../../ansible_mitogen/plugins/strategy action_plugins = lib/action diff --git a/tests/ansible/gcloud-ansible-playbook.py b/tests/ansible/lib/inventory/gcloud.py similarity index 72% rename from tests/ansible/gcloud-ansible-playbook.py rename to tests/ansible/lib/inventory/gcloud.py index 77dd6d99..b537ae74 100755 --- a/tests/ansible/gcloud-ansible-playbook.py +++ b/tests/ansible/lib/inventory/gcloud.py @@ -1,8 +1,13 @@ #!/usr/bin/env python +import json import os import sys +if not os.environ.get('MITOGEN_GCLOUD_GROUP'): + sys.stdout.write('{}') + sys.exit(0) + import googleapiclient.discovery @@ -24,11 +29,12 @@ def main(): #for config in interface['accessConfigs'] ) - print 'Addresses:', ips - os.execvp('ansible-playbook', [ - 'anisble-playbook', - '--inventory-file=' + ','.join(ips) + ',' - ] + sys.argv[1:]) + sys.stderr.write('Addresses: %s\n' % (ips,)) + sys.stdout.write(json.dumps({ + os.environ['MITOGEN_GCLOUD_GROUP']: { + 'hosts': ips + } + }, indent=4)) if __name__ == '__main__':