diff options
author | Thomas Wiest <twiest@users.noreply.github.com> | 2015-03-25 17:22:23 -0400 |
---|---|---|
committer | Thomas Wiest <twiest@users.noreply.github.com> | 2015-03-25 17:22:23 -0400 |
commit | 12bd0ef3541cdb360583afad428f78f83a5222ff (patch) | |
tree | 0d2680de10c529e631bcf77c7c1aea33e297ee1f | |
parent | 08fbdf801ea69761d8337b17b0f2b5df07fdc5a1 (diff) | |
parent | f79f6d649a4c8599121d9cad5492afc579f0425a (diff) | |
download | openshift-12bd0ef3541cdb360583afad428f78f83a5222ff.tar.gz openshift-12bd0ef3541cdb360583afad428f78f83a5222ff.tar.bz2 openshift-12bd0ef3541cdb360583afad428f78f83a5222ff.tar.xz openshift-12bd0ef3541cdb360583afad428f78f83a5222ff.zip |
Merge pull request #124 from twiest/pr
added the ability to have a config file in /etc/openshift_ansible to multi_ec2.py.
-rwxr-xr-x | inventory/multi_ec2.py | 17 | ||||
-rw-r--r-- | inventory/openshift-ansible-inventory.spec | 6 |
2 files changed, 19 insertions, 4 deletions
diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index 5dee7972b..26c09d712 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -12,6 +12,8 @@ import json import pprint +CONFIG_FILE_NAME = 'multi_ec2.yaml' + class MultiEc2(object): def __init__(self): @@ -20,11 +22,22 @@ class MultiEc2(object): 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__))) - self.config_file = os.path.join(self.file_path,"multi_ec2.yaml") + + same_dir_config_file = os.path.join(self.file_path, CONFIG_FILE_NAME) + etc_dir_config_file = os.path.join(os.path.sep, 'etc','ansible', CONFIG_FILE_NAME) + + # Prefer a file in the same directory, fall back to a file in etc + if os.path.isfile(same_dir_config_file): + self.config_file = same_dir_config_file + elif os.path.isfile(etc_dir_config_file): + self.config_file = etc_dir_config_file + else: + self.config_file = None # expect env vars + self.parse_cli_args() # load yaml - if os.path.isfile(self.config_file): + if self.config_file and os.path.isfile(self.config_file): self.config = self.load_yaml_config() elif os.environ.has_key("AWS_ACCESS_KEY_ID") and os.environ.has_key("AWS_SECRET_ACCESS_KEY"): self.config = {} diff --git a/inventory/openshift-ansible-inventory.spec b/inventory/openshift-ansible-inventory.spec index e847df189..9b721818e 100644 --- a/inventory/openshift-ansible-inventory.spec +++ b/inventory/openshift-ansible-inventory.spec @@ -18,18 +18,20 @@ Ansible Inventories used with the openshift-ansible scripts and playbooks. %build %install +mkdir -p %{buildroot}/etc/ansible mkdir -p %{buildroot}/usr/share/ansible/inventory mkdir -p %{buildroot}/usr/share/ansible/inventory/aws mkdir -p %{buildroot}/usr/share/ansible/inventory/gce -cp -p multi_ec2.py multi_ec2.yaml.example %{buildroot}/usr/share/ansible/inventory +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 %files +%config(noreplace) /etc/ansible/* %dir /usr/share/ansible/inventory /usr/share/ansible/inventory/multi_ec2.py* -/usr/share/ansible/inventory/multi_ec2.yaml.example /usr/share/ansible/inventory/aws/ec2.py* %config(noreplace) /usr/share/ansible/inventory/aws/ec2.ini /usr/share/ansible/inventory/gce/gce.py* |