Use sudo for role testing

There are 2 ways to realize the privilege escalation
needed for the gate jobs.

1) Editing the playbooks (and hope to not forget to
write the sudo/become lines for every role)
2) Editing the inventory and set the variable there.

I'm taking the second approach with the minimum set
of variables (become_method is sudo by default and
become_user is root by default).

Change-Id: Iac16f49b514f41684b319e3d091b52513f721b55
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Jean-Philippe Evrard 2015-11-25 13:55:06 +01:00 committed by Kevin Carter
parent 8f8cf55edd
commit ddad475511
No known key found for this signature in database
GPG Key ID: 69FEFFC5E2D9273F
3 changed files with 18 additions and 4 deletions

View File

@ -1,3 +1,3 @@
[defaults]
roles_path = ../../
remote_tmp = ../.ansible/tmp/

View File

@ -1,3 +1,2 @@
[all]
localhost ansible_connection=local physical_host=localhost
localhost ansible_connection=local physical_host=localhost ansible_become=True

View File

@ -16,6 +16,18 @@
- name: Playbook for pre-role testing
hosts: localhost
connection: local
pre_tasks:
- name: Ensure root ssh key
user:
name: "{{ ansible_env.USER | default('root') }}"
generate_ssh_key: "yes"
ssh_key_bits: 2048
ssh_key_file: ".ssh/id_rsa"
- name: get the calling users key
command: cat ~/.ssh/id_rsa.pub
register: key_get
- set_fact:
lxc_container_ssh_key: key_get.stdout
roles:
- role: "lxc_hosts"
lxc_net_address: 10.100.100.1
@ -51,6 +63,7 @@
hostname: "{{ item.name }}"
inventory_hostname: "{{ item.name }}"
ansible_ssh_host: "{{ item.address }}"
ansible_become: true
properties:
service_name: "{{ item.service }}"
container_networks:
@ -82,7 +95,9 @@
register: lxc_containers
- name: Format output
set_fact:
lxc_output: "{{ lxc_containers.stdout | replace(' ', ' ') | lower }}"
_lxc_output: "{{ lxc_containers.stdout.split() | lower }}"
- set_fact:
lxc_output: "{{ _lxc_output | join(' ') }}"
- name: Check role functions
assert:
that: