summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorBrenton Leanhardt <bleanhar@redhat.com>2015-11-05 09:14:33 -0500
committerBrenton Leanhardt <bleanhar@redhat.com>2015-11-05 09:37:43 -0500
commitcfca7b9f7894e2b427ae0753477cd13cc537e348 (patch)
treeec5e1a2c68d3c9c19c94ca17fa97ad8b17614c27 /utils
parent82b4209c02c27ab0e9a6d9c016ff06d12f42a9c1 (diff)
downloadopenshift-cfca7b9f7894e2b427ae0753477cd13cc537e348.tar.gz
openshift-cfca7b9f7894e2b427ae0753477cd13cc537e348.tar.bz2
openshift-cfca7b9f7894e2b427ae0753477cd13cc537e348.tar.xz
openshift-cfca7b9f7894e2b427ae0753477cd13cc537e348.zip
Bug 1274201 - Fixing non-root installations if using a local connection
Previously we were writing out a inventory like this: ~~~ [OSEv3:children] masters nodes [OSEv3:vars] ansible_ssh_user=root deployment_type=openshift-enterprise ansible_connection=local [masters] ose3-master.example.com openshift_hostname=ose3-master.example.com [nodes] ose3-master.example.com openshift_hostname=ose3-master.example.com ose3-node1.example.com openshift_hostname=ose3-node1.example.com ose3-node2.example.com openshift_hostname=ose3-node2.example.com ~~~ The problem with that is now all the hosts are consider local connections. In addition our sudo check wasn't working as expected. We would check that we have sudo, but the playbooks were not running with root privileges. When gathering facts you'd hit: ~~~ __main__.OpenShiftFactsFileWriteError: Could not create fact file: /etc/ansible/facts.d/openshift.fact, error: [Errno 13] Permission denied: '/etc/ansible/facts.d/openshift.fact' ~~~ Instead the test for locale connections needs to be per host. Anytime we're not running as root we need `ansible_become` set: ~~~ ose3-master.example.com openshift_hostname=ose3-master.example.com ansible_connection=local ansible_become=true ~~~
Diffstat (limited to 'utils')
-rw-r--r--utils/src/ooinstall/openshift_ansible.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/utils/src/ooinstall/openshift_ansible.py b/utils/src/ooinstall/openshift_ansible.py
index bdb9859a2..4b37be278 100644
--- a/utils/src/ooinstall/openshift_ansible.py
+++ b/utils/src/ooinstall/openshift_ansible.py
@@ -18,7 +18,6 @@ def set_config(cfg):
def generate_inventory(hosts):
global CFG
- installer_host = socket.gethostname()
base_inventory_path = CFG.settings['ansible_inventory_path']
base_inventory = open(base_inventory_path, 'w')
base_inventory.write('\n[OSEv3:children]\nmasters\nnodes\n')
@@ -44,14 +43,6 @@ def generate_inventory(hosts):
if 'OO_INSTALL_STAGE_REGISTRY' in os.environ:
base_inventory.write('oreg_url=registry.access.stage.redhat.com/openshift3/ose-${component}:${version}\n')
- if any(host.hostname == installer_host or host.public_hostname == installer_host
- for host in hosts):
- no_pwd_sudo = subprocess.call(['sudo', '-v', '-n'])
- if no_pwd_sudo == 1:
- print 'The atomic-openshift-installer requires sudo access without a password.'
- sys.exit(1)
- base_inventory.write("ansible_connection=local\n")
-
base_inventory.write('\n[masters]\n')
masters = (host for host in hosts if host.master)
for master in masters:
@@ -72,6 +63,7 @@ def generate_inventory(hosts):
def write_host(host, inventory, scheduleable=True):
global CFG
+
facts = ''
if host.ip:
facts += ' openshift_ip={}'.format(host.ip)
@@ -85,6 +77,16 @@ def write_host(host, inventory, scheduleable=True):
# Technically only nodes will ever need this.
if not scheduleable:
facts += ' openshift_scheduleable=False'
+ installer_host = socket.gethostname()
+ if host.hostname == installer_host or host.public_hostname == installer_host:
+ facts += ' ansible_connection=local'
+ if os.geteuid() != 0:
+ no_pwd_sudo = subprocess.call(['sudo', '-v', '-n'])
+ if no_pwd_sudo == 1:
+ print 'The atomic-openshift-installer requires sudo access without a password.'
+ sys.exit(1)
+ facts += ' ansible_become=true'
+
inventory.write('{} {}\n'.format(host, facts))