From b0be2e93276c47243dc637d15799cc849776024a Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Tue, 18 Apr 2017 20:53:56 -0700 Subject: [PATCH] Fix role gate tests for Ansible 2.3 In Ansible 2.3, 'ansible_user' seems to be undefined unless set within the inventory for a host. 'ansible_user_id' contains the current user running Ansible, but is only set after facts are gathered. Change-Id: Id5b76a87809f03951c954fc3d752419a673403f7 --- test-install-openstack-hosts.yml | 1 + test-prepare-host.yml | 2 ++ test-prepare-keys.yml | 25 ++++++++++++------------- test-setup-cinder-localhost.yml | 1 + tests/inventory | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/test-install-openstack-hosts.yml b/test-install-openstack-hosts.yml index ff96c288..77371a66 100644 --- a/test-install-openstack-hosts.yml +++ b/test-install-openstack-hosts.yml @@ -16,6 +16,7 @@ - name: Execute the openstack-host role hosts: localhost connection: local + become: true gather_facts: true pre_tasks: - include: "common-tasks/test-force-package-cache-update.yml" diff --git a/test-prepare-host.yml b/test-prepare-host.yml index 993ac3f8..18a6f048 100644 --- a/test-prepare-host.yml +++ b/test-prepare-host.yml @@ -15,6 +15,7 @@ - name: Playbook for configuring hosts hosts: localhost + become: true pre_tasks: - include: "common-tasks/test-set-nodepool-vars.yml" - name: Clear iptables rules @@ -31,6 +32,7 @@ - name: Playbook for configuring the LXC host hosts: localhost + become: true roles: - role: "lxc_hosts" lxc_net_address: 10.100.100.1 diff --git a/test-prepare-keys.yml b/test-prepare-keys.yml index 1eb3f346..3068d579 100644 --- a/test-prepare-keys.yml +++ b/test-prepare-keys.yml @@ -59,12 +59,11 @@ - name: Playbook for establishing user ssh keys hosts: localhost connection: local - gather_facts: false become: false tasks: # Shell used because facts may not be ready yet - name: Get user home directory - shell: "getent passwd '{{ ansible_user }}' | cut -d':' -f6" + shell: "getent passwd '{{ ansible_user_id }}' | cut -d':' -f6" register: user_home changed_when: false @@ -76,31 +75,31 @@ file: path: "{{ calling_user_home }}/.ssh" state: directory - owner: "{{ ansible_user }}" - group: "{{ ansible_user }}" + owner: "{{ ansible_user_id }}" + group: "{{ ansible_user_id }}" mode: 0700 - when: ansible_user != 'root' + when: ansible_user_id != 'root' - name: Ensure user has the known private key copy: content: "{{ root_private_key }}" dest: "{{ calling_user_home }}/.ssh/id_rsa" - owner: "{{ ansible_user }}" - group: "{{ ansible_user }}" + owner: "{{ ansible_user_id }}" + group: "{{ ansible_user_id }}" mode: "0600" - when: ansible_user != 'root' + when: ansible_user_id != 'root' - name: Ensure user has the known public key copy: content: "{{ root_public_key }}" dest: "{{ calling_user_home }}/.ssh/id_rsa.pub" - owner: "{{ ansible_user }}" - group: "{{ ansible_user }}" + owner: "{{ ansible_user_id }}" + group: "{{ ansible_user_id }}" mode: "0600" - when: ansible_user != 'root' + when: ansible_user_id != 'root' - name: Ensure local user can ssh to localhost authorized_key: - user: "{{ ansible_user }}" + user: "{{ ansible_user_id }}" key: "{{ root_public_key }}" - when: ansible_user != 'root' + when: ansible_user_id != 'root' diff --git a/test-setup-cinder-localhost.yml b/test-setup-cinder-localhost.yml index 7148a681..e3da2b59 100644 --- a/test-setup-cinder-localhost.yml +++ b/test-setup-cinder-localhost.yml @@ -15,6 +15,7 @@ - name: Prepare cinder-volumes volume group hosts: localhost + become: true tasks: - name: Install lvm2 apt package apt: diff --git a/tests/inventory b/tests/inventory index 89bf7d25..aeba3afa 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1,5 +1,5 @@ [all] -localhost ansible_become=True +localhost infra1 ansible_host=10.1.0.2 ansible_become=True ansible_user=root keystone1 ansible_host=10.1.0.3 ansible_become=True ansible_user=root