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
This commit is contained in:
Jimmy McCrory 2017-04-18 20:53:56 -07:00
parent b02c3c619b
commit b0be2e9327
5 changed files with 17 additions and 14 deletions

View File

@ -16,6 +16,7 @@
- name: Execute the openstack-host role - name: Execute the openstack-host role
hosts: localhost hosts: localhost
connection: local connection: local
become: true
gather_facts: true gather_facts: true
pre_tasks: pre_tasks:
- include: "common-tasks/test-force-package-cache-update.yml" - include: "common-tasks/test-force-package-cache-update.yml"

View File

@ -15,6 +15,7 @@
- name: Playbook for configuring hosts - name: Playbook for configuring hosts
hosts: localhost hosts: localhost
become: true
pre_tasks: pre_tasks:
- include: "common-tasks/test-set-nodepool-vars.yml" - include: "common-tasks/test-set-nodepool-vars.yml"
- name: Clear iptables rules - name: Clear iptables rules
@ -31,6 +32,7 @@
- name: Playbook for configuring the LXC host - name: Playbook for configuring the LXC host
hosts: localhost hosts: localhost
become: true
roles: roles:
- role: "lxc_hosts" - role: "lxc_hosts"
lxc_net_address: 10.100.100.1 lxc_net_address: 10.100.100.1

View File

@ -59,12 +59,11 @@
- name: Playbook for establishing user ssh keys - name: Playbook for establishing user ssh keys
hosts: localhost hosts: localhost
connection: local connection: local
gather_facts: false
become: false become: false
tasks: tasks:
# Shell used because facts may not be ready yet # Shell used because facts may not be ready yet
- name: Get user home directory - 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 register: user_home
changed_when: false changed_when: false
@ -76,31 +75,31 @@
file: file:
path: "{{ calling_user_home }}/.ssh" path: "{{ calling_user_home }}/.ssh"
state: directory state: directory
owner: "{{ ansible_user }}" owner: "{{ ansible_user_id }}"
group: "{{ ansible_user }}" group: "{{ ansible_user_id }}"
mode: 0700 mode: 0700
when: ansible_user != 'root' when: ansible_user_id != 'root'
- name: Ensure user has the known private key - name: Ensure user has the known private key
copy: copy:
content: "{{ root_private_key }}" content: "{{ root_private_key }}"
dest: "{{ calling_user_home }}/.ssh/id_rsa" dest: "{{ calling_user_home }}/.ssh/id_rsa"
owner: "{{ ansible_user }}" owner: "{{ ansible_user_id }}"
group: "{{ ansible_user }}" group: "{{ ansible_user_id }}"
mode: "0600" mode: "0600"
when: ansible_user != 'root' when: ansible_user_id != 'root'
- name: Ensure user has the known public key - name: Ensure user has the known public key
copy: copy:
content: "{{ root_public_key }}" content: "{{ root_public_key }}"
dest: "{{ calling_user_home }}/.ssh/id_rsa.pub" dest: "{{ calling_user_home }}/.ssh/id_rsa.pub"
owner: "{{ ansible_user }}" owner: "{{ ansible_user_id }}"
group: "{{ ansible_user }}" group: "{{ ansible_user_id }}"
mode: "0600" mode: "0600"
when: ansible_user != 'root' when: ansible_user_id != 'root'
- name: Ensure local user can ssh to localhost - name: Ensure local user can ssh to localhost
authorized_key: authorized_key:
user: "{{ ansible_user }}" user: "{{ ansible_user_id }}"
key: "{{ root_public_key }}" key: "{{ root_public_key }}"
when: ansible_user != 'root' when: ansible_user_id != 'root'

View File

@ -15,6 +15,7 @@
- name: Prepare cinder-volumes volume group - name: Prepare cinder-volumes volume group
hosts: localhost hosts: localhost
become: true
tasks: tasks:
- name: Install lvm2 apt package - name: Install lvm2 apt package
apt: apt:

View File

@ -1,5 +1,5 @@
[all] [all]
localhost ansible_become=True localhost
infra1 ansible_host=10.1.0.2 ansible_become=True ansible_user=root 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 keystone1 ansible_host=10.1.0.3 ansible_become=True ansible_user=root