From 5f09b0e1d3b27fb81473bfd92d424358505969e5 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Fri, 1 May 2015 11:29:40 -0400 Subject: openshift_fact and misc fixes - Do not attempt to fetch file to same file location when playbooks are run locally on master - Fix for openshift_facts when run against a host in a VPC that does not assign internal/external hostnames or ips - Fix setting of labels and annotations on node instances and in openshift_facts - converted openshift_facts to use json for local_fact storage instead of an ini file, included code that should migrate existing ini users to json - added region/zone setting to byo inventory - Fix fact related bug where deployment_type was being set on node role instead of common role for node hosts --- inventory/byo/hosts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'inventory') diff --git a/inventory/byo/hosts b/inventory/byo/hosts index 98dbb4fd8..728eec8aa 100644 --- a/inventory/byo/hosts +++ b/inventory/byo/hosts @@ -20,7 +20,8 @@ deployment_type=enterprise openshift_registry_url=docker-buildvm-rhose.usersys.redhat.com:5000/openshift3_beta/ose-${component}:${version} # Pre-release additional repo -openshift_additional_repos=[{'id': 'ose-devel', 'name': 'ose-devel', 'baseurl': 'http://buildvm-devops.usersys.redhat.com/puddle/build/OpenShiftEnterprise/3.0/latest/RH7-RHOSE-3.0/$basearch/os', 'enabled': 1, 'gpgcheck': 0}] +#openshift_additional_repos=[{'id': 'ose-devel', 'name': 'ose-devel', 'baseurl': 'http://buildvm-devops.usersys.redhat.com/puddle/build/OpenShiftEnterprise/3.0/latest/RH7-RHOSE-3.0/$basearch/os', 'enabled': 1, 'gpgcheck': 0}] +openshift_additional_repos=[{'id': 'ose-devel', 'name': 'ose-devel', 'baseurl': 'http://buildvm-devops.usersys.redhat.com/puddle/build/OpenShiftEnterpriseErrata/3.0/latest/RH7-RHOSE-3.0/$basearch/os', 'enabled': 1, 'gpgcheck': 0}] # Origin copr repo #openshift_additional_repos=[{'id': 'openshift-origin-copr', 'name': 'OpenShift Origin COPR', 'baseurl': 'https://copr-be.cloud.fedoraproject.org/results/maxamillion/origin-next/epel-7-$basearch/', 'enabled': 1, 'gpgcheck': 1, gpgkey: 'https://copr-be.cloud.fedoraproject.org/results/maxamillion/origin-next/pubkey.gpg'}] @@ -31,4 +32,5 @@ ose3-master-ansible.test.example.com # host group for nodes [nodes] -ose3-node[1:2]-ansible.test.example.com +ose3-master-ansible.test.example.com openshift_node_labels="{'region': 'infra', 'zone': 'default'}" +ose3-node[1:2]-ansible.test.example.com openshift_node_labels="{'region': 'primary', 'zone': 'default'}" -- cgit v1.2.3 From b54e8f81469807cdd6cc57d3c03b22ee1212b4cc Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 7 May 2015 11:09:00 -0400 Subject: Allow option in multi_ec2 to set cache location. --- inventory/multi_ec2.py | 26 ++++++++++++++++++++++++-- inventory/multi_ec2.yaml.example | 3 +++ 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'inventory') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index b839a33ea..b99212dd5 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -11,9 +11,12 @@ import yaml import os import subprocess import json +import errno +import fcntl CONFIG_FILE_NAME = 'multi_ec2.yaml' +DEFAULT_CACHE_PATH = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache') class MultiEc2(object): ''' @@ -27,7 +30,6 @@ class MultiEc2(object): self.config = None self.all_ec2_results = {} self.result = {} - self.cache_path = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache') self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__))) same_dir_config_file = os.path.join(self.file_path, CONFIG_FILE_NAME) @@ -48,10 +50,12 @@ class MultiEc2(object): self.config = self.load_yaml_config() elif os.environ.has_key("AWS_ACCESS_KEY_ID") and \ os.environ.has_key("AWS_SECRET_ACCESS_KEY"): + # Build a default config self.config = {} self.config['accounts'] = [ { 'name': 'default', + 'cache_location': DEFAULT_CACHE_PATH, 'provider': 'aws/hosts/ec2.py', 'env_vars': { 'AWS_ACCESS_KEY_ID': os.environ["AWS_ACCESS_KEY_ID"], @@ -64,6 +68,11 @@ class MultiEc2(object): else: raise RuntimeError("Could not find valid ec2 credentials in the environment.") + # Set the default cache path but if its defined we'll assign it. + self.cache_path = DEFAULT_CACHE_PATH + if self.config.has_key('cache_location'): + self.cache_path = self.config['cache_location'] + if self.args.refresh_cache: self.get_inventory() self.write_to_cache() @@ -222,9 +231,22 @@ class MultiEc2(object): def write_to_cache(self): ''' Writes data in JSON format to a file ''' + # if it does not exist, try and create it. + if not os.path.isfile(self.cache_path): + path = os.path.dirname(self.cache_path) + try: + os.makedirs(path) + except OSError as exc: + if exc.errno != errno.EEXIST or not os.path.isdir(path): + raise + json_data = MultiEc2.json_format_dict(self.result, True) with open(self.cache_path, 'w') as cache: - cache.write(json_data) + try: + fcntl.flock(cache, fcntl.LOCK_EX) + cache.write(json_data) + finally: + fcntl.flock(cache, fcntl.LOCK_UN) def get_inventory_from_cache(self): ''' Reads the inventory from the cache file and returns it as a JSON diff --git a/inventory/multi_ec2.yaml.example b/inventory/multi_ec2.yaml.example index 91e7c7970..d8361a49f 100644 --- a/inventory/multi_ec2.yaml.example +++ b/inventory/multi_ec2.yaml.example @@ -1,4 +1,7 @@ # multi ec2 inventory configs +# +cache_location: ~/.ansible/tmp/multi_ec2_inventory.cache + accounts: - name: aws1 provider: aws/hosts/ec2.py -- cgit v1.2.3 From 23a645ada56ef405a476db1f616c8389a4b6639d Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Thu, 7 May 2015 16:44:47 -0400 Subject: fixed build problems with openshift-ansible-inventory.spec --- inventory/openshift-ansible-inventory.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index 8267e16f6..c3b6aa8c8 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -25,8 +25,8 @@ mkdir -p %{buildroot}/usr/share/ansible/inventory/gce cp -p multi_ec2.py %{buildroot}/usr/share/ansible/inventory cp -p multi_ec2.yaml.example %{buildroot}/etc/ansible/multi_ec2.yaml -cp -p aws/ec2.py aws/ec2.ini %{buildroot}/usr/share/ansible/inventory/aws -cp -p gce/gce.py %{buildroot}/usr/share/ansible/inventory/gce +cp -p aws/hosts/ec2.py aws/hosts/ec2.ini %{buildroot}/usr/share/ansible/inventory/aws +cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce %files %config(noreplace) /etc/ansible/* -- cgit v1.2.3 From 9cf97c888698a6fda1a03f0eb5ae5bd74ee2408b Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Thu, 7 May 2015 16:48:25 -0400 Subject: Automatic commit of package [openshift-ansible-inventory] release [0.0.3-1]. --- inventory/openshift-ansible-inventory.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index c3b6aa8c8..f7ca67138 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -1,6 +1,6 @@ Summary: OpenShift Ansible Inventories Name: openshift-ansible-inventory -Version: 0.0.2 +Version: 0.0.3 Release: 1%{?dist} License: ASL 2.0 URL: https://github.com/openshift/openshift-ansible @@ -37,6 +37,13 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce /usr/share/ansible/inventory/gce/gce.py* %changelog +* Thu May 07 2015 Thomas Wiest 0.0.3-1 +- fixed build problems with openshift-ansible-inventory.spec + (twiest@redhat.com) +- Allow option in multi_ec2 to set cache location. (kwoodson@redhat.com) +- Add ansible_connection=local to localhost in inventory (jdetiber@redhat.com) +- Adding refresh-cache option and cleanup for pylint. Also updated for + aws/hosts/ being added. (kwoodson@redhat.com) * Thu Mar 26 2015 Thomas Wiest 0.0.2-1 - added the ability to have a config file in /etc/openshift_ansible to multi_ec2.py. (twiest@redhat.com) -- cgit v1.2.3 From c6c0463a54af4bdab6810697a1ab5f81ef782f4d Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 7 May 2015 17:36:08 -0400 Subject: Fixed a bug due to renaming of variables. --- inventory/multi_ec2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inventory') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index b839a33ea..35ac6c7a8 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -182,7 +182,7 @@ class MultiEc2(object): elif isinstance(input_a[key], list) and isinstance(input_b[key], list): for result in input_b[key]: if result not in input_a[key]: - input_a[key].input_append(result) + input_a[key].append(result) # a is a list and not b elif isinstance(input_a[key], list): if input_b[key] not in input_a[key]: -- cgit v1.2.3 From 4705af597cee2ff523aaede4bb2479c0fc6af430 Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Thu, 7 May 2015 18:47:03 -0400 Subject: Automatic commit of package [openshift-ansible-inventory] release [0.0.4-1]. --- inventory/openshift-ansible-inventory.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index f7ca67138..e6bf37988 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -1,6 +1,6 @@ Summary: OpenShift Ansible Inventories Name: openshift-ansible-inventory -Version: 0.0.3 +Version: 0.0.4 Release: 1%{?dist} License: ASL 2.0 URL: https://github.com/openshift/openshift-ansible @@ -37,6 +37,9 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce /usr/share/ansible/inventory/gce/gce.py* %changelog +* Thu May 07 2015 Thomas Wiest 0.0.4-1 +- Fixed a bug due to renaming of variables. (kwoodson@redhat.com) + * Thu May 07 2015 Thomas Wiest 0.0.3-1 - fixed build problems with openshift-ansible-inventory.spec (twiest@redhat.com) -- cgit v1.2.3 From 7c905c0cf962ec9b7f5bd140a506bd614831f0e8 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Tue, 12 May 2015 12:20:11 -0400 Subject: Added capability to pass in ec2.ini file. --- inventory/multi_ec2.py | 74 ++++++++++++++++++++++++++++------------ inventory/multi_ec2.yaml.example | 10 ++++++ 2 files changed, 63 insertions(+), 21 deletions(-) (limited to 'inventory') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index 063a80300..d251c6a6a 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -13,7 +13,7 @@ import subprocess import json import errno import fcntl - +import tempfile CONFIG_FILE_NAME = 'multi_ec2.yaml' DEFAULT_CACHE_PATH = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache') @@ -128,6 +128,54 @@ class MultiEc2(object): return subprocess.Popen(cmds, stderr=subprocess.PIPE, \ stdout=subprocess.PIPE, env=env) + + @staticmethod + def generate_config(config_data): + """Generate the ec2.ini file in as a secure temp file. + Once generated, pass it to the ec2.py as an environment variable. + """ + fildes, tmp_file_path = tempfile.mkstemp(prefix='multi_ec2.ini.') + for section, values in config_data.items(): + os.write(fildes, "[%s]\n" % section) + for option, value in values.items(): + os.write(fildes, "%s = %s\n" % (option, value)) + os.close(fildes) + return tmp_file_path + + def run_provider(self): + '''Setup the provider call with proper variables + and call self.get_provider_tags. + ''' + try: + all_results = [] + tmp_file_path = None + processes = {} + for account in self.config['accounts']: + env = account['env_vars'] + if account.has_key('provider_config'): + tmp_file_path = MultiEc2.generate_config(account['provider_config']) + env['EC2_INI_PATH'] = tmp_file_path + name = account['name'] + provider = account['provider'] + processes[name] = self.get_provider_tags(provider, env) + + # for each process collect stdout when its available + for name, process in processes.items(): + out, err = process.communicate() + all_results.append({ + "name": name, + "out": out.strip(), + "err": err.strip(), + "code": process.returncode + }) + + finally: + # Clean up the mkstemp file + if tmp_file_path: + os.unlink(tmp_file_path) + + return all_results + def get_inventory(self): """Create the subprocess to fetch tags from a provider. Host query: @@ -138,28 +186,12 @@ class MultiEc2(object): Query all of the different accounts for their tags. Once completed store all of their results into one merged updated hash. """ - processes = {} - for account in self.config['accounts']: - env = account['env_vars'] - name = account['name'] - provider = account['provider'] - processes[name] = self.get_provider_tags(provider, env) - - # for each process collect stdout when its available - all_results = [] - for name, process in processes.items(): - out, err = process.communicate() - all_results.append({ - "name": name, - "out": out.strip(), - "err": err.strip(), - "code": process.returncode - }) + provider_results = self.run_provider() # process --host results if not self.args.host: # For any non-zero, raise an error on it - for result in all_results: + for result in provider_results: if result['code'] != 0: raise RuntimeError(result['err']) else: @@ -171,9 +203,9 @@ class MultiEc2(object): else: # For any 0 result, return it count = 0 - for results in all_results: + for results in provider_results: if results['code'] == 0 and results['err'] == '' and results['out'] != '{}': - self.result = json.loads(out) + self.result = json.loads(results['out']) count += 1 if count > 1: raise RuntimeError("Found > 1 results for --host %s. \ diff --git a/inventory/multi_ec2.yaml.example b/inventory/multi_ec2.yaml.example index d8361a49f..c41c134ab 100644 --- a/inventory/multi_ec2.yaml.example +++ b/inventory/multi_ec2.yaml.example @@ -5,6 +5,15 @@ cache_location: ~/.ansible/tmp/multi_ec2_inventory.cache accounts: - name: aws1 provider: aws/hosts/ec2.py + provider_config: + ec2: + regions: all + regions_exclude: us-gov-west-1,cn-north-1 + destination_variable: public_dns_name + route53: False + cache_path: ~/.ansible/tmp + cache_max_age: 300 + vpc_destination_variable: ip_address env_vars: AWS_ACCESS_KEY_ID: XXXXXXXXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX @@ -14,5 +23,6 @@ accounts: env_vars: AWS_ACCESS_KEY_ID: XXXXXXXXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + EC2_INI_PATH: /etc/ansible/ec2.ini cache_max_age: 60 -- cgit v1.2.3 From 4e3972b89a0954b55e7b10917757e07b9e610c3a Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Tue, 12 May 2015 16:37:49 -0400 Subject: removed ec2.ini from the openshift-ansible-inventory.spec file so that we're not dictating what the ec2.ini file should look like. --- inventory/openshift-ansible-inventory.spec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index e6bf37988..c1b066afb 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -25,7 +25,7 @@ mkdir -p %{buildroot}/usr/share/ansible/inventory/gce cp -p multi_ec2.py %{buildroot}/usr/share/ansible/inventory cp -p multi_ec2.yaml.example %{buildroot}/etc/ansible/multi_ec2.yaml -cp -p aws/hosts/ec2.py aws/hosts/ec2.ini %{buildroot}/usr/share/ansible/inventory/aws +cp -p aws/hosts/ec2.py %{buildroot}/usr/share/ansible/inventory/aws cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce %files @@ -33,7 +33,6 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce %dir /usr/share/ansible/inventory /usr/share/ansible/inventory/multi_ec2.py* /usr/share/ansible/inventory/aws/ec2.py* -%config(noreplace) /usr/share/ansible/inventory/aws/ec2.ini /usr/share/ansible/inventory/gce/gce.py* %changelog -- cgit v1.2.3 From 22a2616359ee1f167c85ec21bf416350706a7b5b Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Tue, 12 May 2015 16:47:07 -0400 Subject: Automatic commit of package [openshift-ansible-inventory] release [0.0.5-1]. --- inventory/openshift-ansible-inventory.spec | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index c1b066afb..69bd255d4 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -1,6 +1,6 @@ Summary: OpenShift Ansible Inventories Name: openshift-ansible-inventory -Version: 0.0.4 +Version: 0.0.5 Release: 1%{?dist} License: ASL 2.0 URL: https://github.com/openshift/openshift-ansible @@ -36,6 +36,11 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce /usr/share/ansible/inventory/gce/gce.py* %changelog +* Tue May 12 2015 Thomas Wiest 0.0.5-1 +- removed ec2.ini from the openshift-ansible-inventory.spec file so that we're + not dictating what the ec2.ini file should look like. (twiest@redhat.com) +- Added capability to pass in ec2.ini file. (kwoodson@redhat.com) + * Thu May 07 2015 Thomas Wiest 0.0.4-1 - Fixed a bug due to renaming of variables. (kwoodson@redhat.com) -- cgit v1.2.3 From d82c71ce9a98c1e9ecabf24cd7bd7c7e19aabec2 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Wed, 13 May 2015 16:38:20 -0400 Subject: Added support for grouping and a bug fix. --- inventory/multi_ec2.py | 64 ++++++++++++++++++++++++++++++---------- inventory/multi_ec2.yaml.example | 6 +++- 2 files changed, 53 insertions(+), 17 deletions(-) (limited to 'inventory') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index d251c6a6a..11247f942 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -14,6 +14,7 @@ import json import errno import fcntl import tempfile +import copy CONFIG_FILE_NAME = 'multi_ec2.yaml' DEFAULT_CACHE_PATH = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache') @@ -148,13 +149,13 @@ class MultiEc2(object): ''' try: all_results = [] - tmp_file_path = None + tmp_file_paths = [] processes = {} for account in self.config['accounts']: env = account['env_vars'] if account.has_key('provider_config'): - tmp_file_path = MultiEc2.generate_config(account['provider_config']) - env['EC2_INI_PATH'] = tmp_file_path + tmp_file_paths.append(MultiEc2.generate_config(account['provider_config'])) + env['EC2_INI_PATH'] = tmp_file_paths[-1] name = account['name'] provider = account['provider'] processes[name] = self.get_provider_tags(provider, env) @@ -171,8 +172,8 @@ class MultiEc2(object): finally: # Clean up the mkstemp file - if tmp_file_path: - os.unlink(tmp_file_path) + for tmp_file in tmp_file_paths: + os.unlink(tmp_file) return all_results @@ -189,27 +190,58 @@ class MultiEc2(object): provider_results = self.run_provider() # process --host results - if not self.args.host: + # For any 0 result, return it + if self.args.host: + count = 0 + for results in provider_results: + if results['code'] == 0 and results['err'] == '' and results['out'] != '{}': + self.result = json.loads(results['out']) + count += 1 + if count > 1: + raise RuntimeError("Found > 1 results for --host %s. \ + This is an invalid state." % self.args.host) + # process --list results + else: # For any non-zero, raise an error on it for result in provider_results: if result['code'] != 0: raise RuntimeError(result['err']) else: self.all_ec2_results[result['name']] = json.loads(result['out']) + + # Check if user wants extra vars in yaml by + # having hostvars and all_group defined + for acc_config in self.config['accounts']: + self.apply_account_config(acc_config) + + # Build results by merging all dictionaries values = self.all_ec2_results.values() values.insert(0, self.result) for result in values: MultiEc2.merge_destructively(self.result, result) - else: - # For any 0 result, return it - count = 0 - for results in provider_results: - if results['code'] == 0 and results['err'] == '' and results['out'] != '{}': - self.result = json.loads(results['out']) - count += 1 - if count > 1: - raise RuntimeError("Found > 1 results for --host %s. \ - This is an invalid state." % self.args.host) + + def apply_account_config(self, acc_config): + ''' Apply account config settings + ''' + if not acc_config.has_key('hostvars') and not acc_config.has_key('all_group'): + return + + results = self.all_ec2_results[acc_config['name']] + # Update each hostvar with the newly desired key: value + for host_property, value in acc_config['hostvars'].items(): + # Verify the account results look sane + # by checking for these keys ('_meta' and 'hostvars' exist) + if results.has_key('_meta') and results['_meta'].has_key('hostvars'): + for data in results['_meta']['hostvars'].values(): + data[str(host_property)] = str(value) + + # Add this group + results["%s_%s" % (host_property, value)] = \ + copy.copy(results[acc_config['all_group']]) + + # store the results back into all_ec2_results + self.all_ec2_results[acc_config['name']] = results + @staticmethod def merge_destructively(input_a, input_b): "merges b into input_a" diff --git a/inventory/multi_ec2.yaml.example b/inventory/multi_ec2.yaml.example index c41c134ab..99f157b11 100644 --- a/inventory/multi_ec2.yaml.example +++ b/inventory/multi_ec2.yaml.example @@ -17,8 +17,12 @@ accounts: env_vars: AWS_ACCESS_KEY_ID: XXXXXXXXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + all_group: ec2 + hostvars: + cloud: aws + account: aws1 - - name: aws2 +- name: aws2 provider: aws/hosts/ec2.py env_vars: AWS_ACCESS_KEY_ID: XXXXXXXXXXXXXXXXXXXX -- cgit v1.2.3 From 87e53ef9917556a331a81d8a01195c4ac8679bcd Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Wed, 13 May 2015 16:57:57 -0400 Subject: Automatic commit of package [openshift-ansible-inventory] release [0.0.6-1]. --- inventory/openshift-ansible-inventory.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index 69bd255d4..0fe25ff31 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -1,6 +1,6 @@ Summary: OpenShift Ansible Inventories Name: openshift-ansible-inventory -Version: 0.0.5 +Version: 0.0.6 Release: 1%{?dist} License: ASL 2.0 URL: https://github.com/openshift/openshift-ansible @@ -36,6 +36,9 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce /usr/share/ansible/inventory/gce/gce.py* %changelog +* Wed May 13 2015 Thomas Wiest 0.0.6-1 +- Added support for grouping and a bug fix. (kwoodson@redhat.com) + * Tue May 12 2015 Thomas Wiest 0.0.5-1 - removed ec2.ini from the openshift-ansible-inventory.spec file so that we're not dictating what the ec2.ini file should look like. (twiest@redhat.com) -- cgit v1.2.3 From 2657d56660495476d4e64bf4b1a47ebf277770ee Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 14 May 2015 12:14:27 -0400 Subject: Making multi_ec2 into a library --- inventory/multi_ec2.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'inventory') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index 11247f942..f8196aefd 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -26,8 +26,14 @@ class MultiEc2(object): Stores a json hash of resources in result. ''' - def __init__(self): - self.args = None + def __init__(self, args=None): + # Allow args to be passed when called as a library + if not args: + self.args = {} + else: + self.args = args + + self.cache_path = DEFAULT_CACHE_PATH self.config = None self.all_ec2_results = {} self.result = {} @@ -44,8 +50,15 @@ class MultiEc2(object): else: self.config_file = None # expect env vars - self.parse_cli_args() + def run(self): + '''This method checks to see if the local + cache is valid for the inventory. + + if the cache is valid; return cache + else the credentials are loaded from multi_ec2.yaml or from the env + and we attempt to get the inventory from the provider specified. + ''' # load yaml if self.config_file and os.path.isfile(self.config_file): self.config = self.load_yaml_config() @@ -70,15 +83,14 @@ class MultiEc2(object): raise RuntimeError("Could not find valid ec2 credentials in the environment.") # Set the default cache path but if its defined we'll assign it. - self.cache_path = DEFAULT_CACHE_PATH if self.config.has_key('cache_location'): self.cache_path = self.config['cache_location'] - if self.args.refresh_cache: + if self.args.get('refresh_cache', None): self.get_inventory() self.write_to_cache() # if its a host query, fetch and do not cache - elif self.args.host: + elif self.args.get('host', None): self.get_inventory() elif not self.is_cache_valid(): # go fetch the inventories and cache them if cache is expired @@ -119,9 +131,9 @@ class MultiEc2(object): "and that it is executable. (%s)" % provider) cmds = [provider] - if self.args.host: + if self.args.get('host', None): cmds.append("--host") - cmds.append(self.args.host) + cmds.append(self.args.get('host', None)) else: cmds.append('--list') @@ -191,7 +203,7 @@ class MultiEc2(object): # process --host results # For any 0 result, return it - if self.args.host: + if self.args.get('host', None): count = 0 for results in provider_results: if results['code'] == 0 and results['err'] == '' and results['out'] != '{}': @@ -199,7 +211,7 @@ class MultiEc2(object): count += 1 if count > 1: raise RuntimeError("Found > 1 results for --host %s. \ - This is an invalid state." % self.args.host) + This is an invalid state." % self.args.get('host', None)) # process --list results else: # For any non-zero, raise an error on it @@ -290,7 +302,7 @@ class MultiEc2(object): help='List instances (default: True)') parser.add_argument('--host', action='store', default=False, help='Get all the variables about a specific instance') - self.args = parser.parse_args() + self.args = parser.parse_args().__dict__ def write_to_cache(self): ''' Writes data in JSON format to a file ''' @@ -340,4 +352,7 @@ class MultiEc2(object): if __name__ == "__main__": - print MultiEc2().result_str() + MEC2 = MultiEc2() + MEC2.parse_cli_args() + MEC2.run() + print MEC2.result_str() -- cgit v1.2.3 From 1eda40ef2a4df9c5a6a728ac32d74ee1aaca2676 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Fri, 15 May 2015 14:15:08 -0400 Subject: Automatic commit of package [openshift-ansible-inventory] release [0.0.7-1]. --- inventory/openshift-ansible-inventory.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index 0fe25ff31..7ba6e3df1 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -1,6 +1,6 @@ Summary: OpenShift Ansible Inventories Name: openshift-ansible-inventory -Version: 0.0.6 +Version: 0.0.7 Release: 1%{?dist} License: ASL 2.0 URL: https://github.com/openshift/openshift-ansible @@ -36,6 +36,9 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce /usr/share/ansible/inventory/gce/gce.py* %changelog +* Fri May 15 2015 Kenny Woodson 0.0.7-1 +- Making multi_ec2 into a library (kwoodson@redhat.com) + * Wed May 13 2015 Thomas Wiest 0.0.6-1 - Added support for grouping and a bug fix. (kwoodson@redhat.com) -- cgit v1.2.3 From 890f2c5d039a501966eedbf8c7bb7b7e9b50464a Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Fri, 15 May 2015 14:48:55 -0400 Subject: fixed the openshift-ansible-bin build --- inventory/openshift-ansible-inventory.spec | 1 + 1 file changed, 1 insertion(+) (limited to 'inventory') diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index 7ba6e3df1..cd2332549 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -57,6 +57,7 @@ cp -p gce/hosts/gce.py %{buildroot}/usr/share/ansible/inventory/gce - Add ansible_connection=local to localhost in inventory (jdetiber@redhat.com) - Adding refresh-cache option and cleanup for pylint. Also updated for aws/hosts/ being added. (kwoodson@redhat.com) + * Thu Mar 26 2015 Thomas Wiest 0.0.2-1 - added the ability to have a config file in /etc/openshift_ansible to multi_ec2.py. (twiest@redhat.com) -- cgit v1.2.3