From eca6cd03e794a18fb748a166cf0558df3a2b7325 Mon Sep 17 00:00:00 2001 From: John Fulton Date: Mon, 5 Aug 2019 17:55:01 -0400 Subject: [PATCH] Inherit calling Ansible's environment when running ceph-ansible When config-download runs ceph-ansible it does so by calling Ansible from within Ansible. This change adds a new boolean, ceph_ansible_inherits_calling_ansible_environment (default: true), which passes all ANSIBLE_* environment variables to the nested Ansible execution. If a config-download user exported a variable, e.g. ANSIBLE_PRIVATE_KEY_FILE, then they might be surprised if they got to the Ceph installation and it failed because Ansible was unable to SSH into the target nodes because it didn't have that environment variable set. Rather than require the user to know about the nested execution and use the CephAnsibleEnvironmentVariables parameter, assume they want the same variables passed. Required TripleO defaults for ceph-ansible still take precedence over config-download environment variables; ANSIBLE_ROLES_PATH still refers to ceph-ansible roles, not config-download roles. CephAnsibleEnvironmentVariables takes precedence over both the calling Ansible environment variables and TripleO defaults for ceph-ansible. Change-Id: I428f6deb416b540dae552b5fc7a778cbc7505e8c --- .../tripleo-ceph-common/defaults/main.yml | 1 + .../roles/tripleo-ceph-common/tasks/main.yml | 19 +++++++++++++++++++ .../tripleo-ceph-run-ansible/tasks/main.yml | 1 + .../roles/tripleo-ceph-uuid/tasks/gather.yml | 1 + 4 files changed, 22 insertions(+) diff --git a/tripleo_ansible/roles/tripleo-ceph-common/defaults/main.yml b/tripleo_ansible/roles/tripleo-ceph-common/defaults/main.yml index 8affc23b5..4c7ece3e8 100644 --- a/tripleo_ansible/roles/tripleo-ceph-common/defaults/main.yml +++ b/tripleo_ansible/roles/tripleo-ceph-common/defaults/main.yml @@ -144,3 +144,4 @@ openstack_config: true pools: [] ntp_service_enabled: false generate_fsid: false +ceph_ansible_inherits_calling_ansible_environment: true diff --git a/tripleo_ansible/roles/tripleo-ceph-common/tasks/main.yml b/tripleo_ansible/roles/tripleo-ceph-common/tasks/main.yml index ba3225571..3c71fcfa5 100644 --- a/tripleo_ansible/roles/tripleo-ceph-common/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo-ceph-common/tasks/main.yml @@ -43,3 +43,22 @@ ansible_user_dir: "{{ lookup('env', 'HOME') }}" when: - ansible_user_dir is undefined + +- name: set default for calling_ansible_environment_variables + set_fact: + calling_ansible_environment_variables: [] + +- when: ceph_ansible_inherits_calling_ansible_environment + block: + - name: get all ansible environment variables + shell: "env | grep ANSIBLE_" + register: env_shell_output + ignore_errors: true + - name: set calling_ansible_environment_variables + set_fact: + calling_ansible_environment_variables: "{{ env_shell_output.stdout_lines }}" + when: + - env_shell_output.rc is defined + - env_shell_output.rc == 0 + - env_shell_output.stdout_lines is defined + - (env_shell_output.stdout_lines|length) > 0 diff --git a/tripleo_ansible/roles/tripleo-ceph-run-ansible/tasks/main.yml b/tripleo_ansible/roles/tripleo-ceph-run-ansible/tasks/main.yml index 1672c49c6..e172d102c 100644 --- a/tripleo_ansible/roles/tripleo-ceph-run-ansible/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo-ceph-run-ansible/tasks/main.yml @@ -26,6 +26,7 @@ - name: set ceph-ansible command list set_fact: ceph_ansible_command_list: + - "{{ calling_ansible_environment_variables|join(' ') }}" - ANSIBLE_ACTION_PLUGINS=/usr/share/ceph-ansible/plugins/actions/ - ANSIBLE_CALLBACK_PLUGINS=/usr/share/ceph-ansible/plugins/callback/ - ANSIBLE_ROLES_PATH=/usr/share/ceph-ansible/roles/ diff --git a/tripleo_ansible/roles/tripleo-ceph-uuid/tasks/gather.yml b/tripleo_ansible/roles/tripleo-ceph-uuid/tasks/gather.yml index 830e7d512..982a7fedb 100644 --- a/tripleo_ansible/roles/tripleo-ceph-uuid/tasks/gather.yml +++ b/tripleo_ansible/roles/tripleo-ceph-uuid/tasks/gather.yml @@ -17,6 +17,7 @@ - name: build nodes-uuid command as list set_fact: nodes_uuid_list: + - "{{ calling_ansible_environment_variables|join(' ') }}" - ANSIBLE_LOG_PATH="{{ playbook_dir }}/ceph-ansible/nodes_uuid_command.log" - ANSIBLE_SSH_CONTROL_PATH_DIR="{{ playbook_dir }}/ceph-ansible/" - ANSIBLE_CONFIG="{{ playbook_dir }}/ansible.cfg"