Replace the native quickstart inventory with ansible-role-tripleo-inventory

- Inventory is a core feature of a virt provisioning tool. At the
moment, quickstart is pulling in art-inventory [1] via requirements.txt.
This patch is dumping art-inventory [1] directly into quickstart itself.
- Convert roles/tripleo-inventory/README.md in rst format.
- Remove some extra newlines at end of file.
- Remove unnecessary files and directory.

[1] - https://github.com/redhat-openstack/ansible-role-tripleo-inventory

Change-Id: I1f20a69ca13de99eda0d98a26c63c66524b22dc8
Closes-Bug: 1604517
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2016-08-16 16:15:47 +02:00
parent c171e32aaa
commit 2dbde3f515
11 changed files with 352 additions and 3 deletions

View File

@ -2,6 +2,3 @@ ansible==2.1.0
netaddr>=0.7.18
pbr>=1.6
setuptools>=11.3
# Roles
git+https://github.com/redhat-openstack/ansible-role-tripleo-inventory.git#egg=ansible-role-tripleo-inventory

View File

@ -0,0 +1,14 @@
---
# Working directory on the slave running the playbook,
local_working_dir: "{{ lookup('env', 'HOME') }}/.quickstart"
# Working directory on the virthost.
working_dir: /home/stack
# Ansible user name.
ansible_user: stack
# SSH key used to access the undercloud machine.
undercloud_key: "{{ local_working_dir }}/id_rsa_undercloud"
# Default to 'undercloud' if the overcloud has not been deployed yet, or 'all'
# in case we want to inventory all the hosts.
inventory: undercloud
# Type of undercloud.
undercloud_type: virtual

View File

@ -0,0 +1,121 @@
---
- name: Ensure gather_facts has been run against localhost
setup:
delegate_to: localhost
delegate_facts: True
when: hostvars['localhost'].ansible_user_dir is not defined
- when: inventory == 'all'
block:
#required for liberty based deployments
- name: copy get-overcloud-nodes.py to undercloud
template:
src: 'get-overcloud-nodes.py.j2'
dest: '{{ working_dir }}/get-overcloud-nodes.py'
mode: 0755
#required for liberty based deployments
- name: fetch overcloud node names and IPs
shell: >
source {{ working_dir }}/stackrc;
python {{ working_dir }}/get-overcloud-nodes.py
register: registered_overcloud_nodes
- name: list the overcloud nodes
debug: var=registered_overcloud_nodes.stdout
- name: fetch the undercloud ssh key
fetch:
src: '{{ working_dir }}/.ssh/id_rsa'
dest: '{{ local_working_dir }}/id_rsa_overcloud'
flat: yes
mode: 0400
# add host to the ansible group formed from its type
# novacompute nodes are added as compute for backwards compatibility
- name: add overcloud node to ansible
with_dict: '{{ registered_overcloud_nodes.stdout | default({}) }}'
add_host:
name: '{{ item.key }}'
groups: "overcloud,{{ item.key | regex_replace('overcloud-(?:nova)?([a-zA-Z0-9_]+)-[0-9]+$', '\\1') }}"
ansible_host: '{{ item.key }}'
ansible_fqdn: '{{ item.value }}'
ansible_user: 'heat-admin'
ansible_private_key_file: "{{ local_working_dir }}/id_rsa_overcloud"
#required for regeneration of ssh.config.ansible
- name: set_fact for undercloud ip
set_fact: undercloud_ip={{ hostvars['undercloud'].undercloud_ip }}
when: hostvars['undercloud'] is defined and hostvars['undercloud'].undercloud_ip is defined
#readd the undercloud to reset the ansible_ssh parameters set in quickstart
- name: Add undercloud vm to inventory
add_host:
name: undercloud
groups: undercloud
ansible_host: undercloud
ansible_fqdn: undercloud
ansible_user: stack
ansible_private_key_file: '{{ local_working_dir }}/id_rsa_undercloud'
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.local.ansible"'
undercloud_ip: "{{ undercloud_ip }}"
when: hostvars[groups['virthost'][0]].ansible_private_key_file is not defined and undercloud_ip is defined
#required for regeneration of ssh.config.ansible
- name: set undercloud ssh proxy command
set_fact: undercloud_ssh_proxy_command="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ hostvars[groups['virthost'][0]].ansible_private_key_file }}
{{ ansible_user }}@{{ hostvars[groups['virthost'][0]].ansible_host }}
-W {{ undercloud_ip }}:22"
when: hostvars[groups['virthost'][0]].ansible_private_key_file is defined and undercloud_ip is defined
#required for regeneration of ssh.config.ansible
- name: set undercloud ssh proxy command
set_fact: undercloud_ssh_proxy_command="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ hostvars['localhost'].ansible_user_dir }}/.quickstart/id_rsa_virt_power
{{ ansible_user }}@{{ hostvars['localhost'].ansible_default_ipv4.address }}
-W {{ undercloud_ip }}:22"
when: hostvars[groups['virthost'][0]].ansible_private_key_file is not defined and undercloud_ip is defined
- name: create inventory from template
delegate_to: localhost
template:
src: 'inventory.j2'
dest: '{{ local_working_dir }}/hosts'
- name: regenerate ssh config
delegate_to: localhost
template:
src: 'ssh_config.j2'
dest: '{{ local_working_dir }}/ssh.config.ansible'
mode: 0755
when: undercloud_ip is defined
- name: regenerate ssh config for ssh connections from the virthost
delegate_to: localhost
template:
src: 'ssh_config_localhost.j2'
dest: '{{ local_working_dir }}/ssh.config.local.ansible'
mode: 0755
when: undercloud_ip is defined
# just setup the ssh.config.ansible and hosts file for the virthost
- name: check for existence of identity key
delegate_to: localhost
stat: path="{{ local_working_dir }}/id_rsa_virt_power"
when: undercloud_ip is not defined
register: result_stat_id_rsa_virt_power
- name: set fact used in ssh_config_no_undercloud.j2 to determine if IdentityFile should be included
set_fact:
id_rsa_virt_power_exists: true
when: undercloud_ip is not defined and result_stat_id_rsa_virt_power.stat.exists == True
- name: regenerate ssh config, if no undercloud has been launched.
delegate_to: localhost
template:
src: 'ssh_config_no_undercloud.j2'
dest: '{{ local_working_dir }}/ssh.config.ansible'
mode: 0755
when: undercloud_ip is not defined

View File

@ -0,0 +1,12 @@
#!/usr/bin/env python
import os
from novaclient import client
nova = client.Client(2,
os.environ.get("OS_USERNAME"),
os.environ.get("OS_PASSWORD"),
os.environ.get("OS_TENANT_NAME"),
os.environ.get("OS_AUTH_URL"))
print {server.name: server.networks['ctlplane'][0] for server in nova.servers.list()}

View File

@ -0,0 +1,26 @@
{% for host in groups['all'] %}
{% if hostvars[host].get('ansible_connection', '') == 'local' %}
{{ host }} ansible_connection=local
{% else %}
{{ host }}{% if 'ansible_host' in hostvars[host]
%} ansible_host={{ hostvars[host]['ansible_host'] }}{% endif %}
{% if 'ansible_user' in hostvars[host]
%} ansible_user={{ hostvars[host]['ansible_user'] }}{% endif %}
{% if 'ansible_private_key_file' in hostvars[host]
%} ansible_private_key_file={{ hostvars[host]['ansible_private_key_file'] }}{% endif %}
{% if 'undercloud_ip' in hostvars[host]
%} undercloud_ip={{ hostvars[host]['undercloud_ip'] }}{% endif %}
{% endif %}
{% endfor %}
{% for group in groups %}
{% if group not in ['ungrouped', 'all'] %}
[{{ group }}]
{% for host in groups[group] %}
{{ host }}
{% endfor %}
{% endif %}
{% endfor %}

View File

@ -0,0 +1,61 @@
{% set ssh_user = ansible_user|default(ansible_user_id, True) %}
{% if ansible_host is not defined or ansible_host == 'localhost' %}
{% set ssh_host = inventory_hostname %}
{% else %}
{% set ssh_host = ansible_host %}
{% endif %}
{% if hostvars[groups['virthost'][0]].ansible_host is defined %}
Host virthost
Hostname {{ hostvars[groups['virthost'][0]].ansible_host }}
IdentityFile {{ local_working_dir }}/id_rsa_virt_power
User {{ ansible_user }}
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% else %}
Host virthost
Hostname {{ hostvars['localhost'].ansible_default_ipv4.address }}
IdentityFile {{ local_working_dir }}/id_rsa_virt_power
User {{ ansible_user }}
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% endif %}
Host undercloud-root
{% if undercloud_type == 'virtual' %}
ProxyCommand {{ undercloud_ssh_proxy_command }}
{% else %}
Hostname {{ undercloud_ip }}
{% endif %}
IdentityFile {{ local_working_dir }}/id_rsa_undercloud
User root
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Host undercloud
{% if undercloud_type == 'virtual' %}
ProxyCommand {{ undercloud_ssh_proxy_command }}
{% else %}
Hostname {{ undercloud_ip }}
{% endif %}
IdentityFile {{ local_working_dir }}/id_rsa_undercloud
User stack
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% if groups["overcloud"] is defined %}
{% for host in groups["overcloud"] %}
Host {{ host }}
ProxyCommand ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=60 -F {{ local_working_dir }}/ssh.config.ansible undercloud -W {{ hostvars[host].ansible_fqdn }}:22
IdentityFile {{ local_working_dir }}/id_rsa_overcloud
User heat-admin
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% endfor %}
{% endif %}

View File

@ -0,0 +1,36 @@
{% set ansible_host = 'localhost' %}
{% set ssh_user = ansible_user|default(ansible_user_id, True) %}
{% if ansible_host is not defined or ansible_host == 'localhost' %}
{% set ssh_host = inventory_hostname %}
{% else %}
{% set ssh_host = ansible_host %}
{% endif %}
Host undercloud-root
Hostname {{ undercloud_ip }}
IdentityFile {{ hostvars['localhost'].ansible_user_dir }}/.quickstart/id_rsa_undercloud
IdentitiesOnly yes
User root
StrictHostKeyChecking no
Host undercloud
Hostname {{ undercloud_ip }}
IdentityFile {{ hostvars['localhost'].ansible_user_dir }}/.quickstart/id_rsa_undercloud
IdentitiesOnly yes
User stack
StrictHostKeyChecking no
{% if groups["overcloud"] is defined %}
{% for host in groups["overcloud"] %}
Host {{ host }}
Hostname {{ hostvars[host].ansible_fqdn }}
ProxyCommand ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=60 -F {{ hostvars['localhost'].ansible_user_dir }}/.quickstart/ssh.config.local.ansible undercloud -W {{ hostvars[host].ansible_fqdn }}:22
IdentityFile {{ hostvars['localhost'].ansible_user_dir }}/.quickstart/id_rsa_overcloud
User heat-admin
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% endfor %}
{% endif %}

View File

@ -0,0 +1,30 @@
{% set ssh_user = ansible_user|default(ansible_user_id, True) %}
{% if ansible_host is not defined or ansible_host == 'localhost' %}
{% set ssh_host = inventory_hostname %}
{% else %}
{% set ssh_host = ansible_host %}
{% endif %}
{% if hostvars[groups['virthost'][0]].ansible_host is defined %}
Host virthost
Hostname {{ hostvars[groups['virthost'][0]].ansible_host }}
{% if id_rsa_virt_power_exists is defined %}
IdentityFile {{ local_working_dir }}/id_rsa_virt_power
{% endif %}
User {{ ansible_user }}
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% else %}
Host virthost
Hostname {{ hostvars['localhost'].ansible_default_ipv4.address }}
{% if id_rsa_virt_power_exists is defined %}
IdentityFile {{ local_working_dir }}/id_rsa_virt_power
{% endif %}
User {{ ansible_user }}
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
{% endif %}

View File

@ -0,0 +1 @@
localhost

View File

@ -0,0 +1,46 @@
# This is the playbook used by the `quickstart.sh` script.
# The [provision.yml](provision.yml.html) playbook is responsible for
# creating an inventory entry for our `virthost` and for creating an
# unprivileged user on that host for use by our virtual environment.
- include: provision.yml
tags:
- provision
# The `environment/setup` role performs any tasks that require `root`
# access on the target host.
- name: Install libvirt packages and configure networks
hosts: virthost
tags:
- environment
roles:
- environment/setup
# The `libvirt/setup` role creates the undercloud and overcloud
# virtual machines.
- name: Setup undercloud and overcloud vms
hosts: virthost
gather_facts: yes
roles:
- libvirt/teardown
- libvirt/setup
# Add the undercloud node to the generated
# inventory.
- name: Inventory the undercloud
hosts: undercloud
gather_facts: no
vars:
inventory: undercloud
roles:
- tripleo-inventory
# DEPLOY ALL THE THINGS! Depending on the currently selected set of
# tags, this will deploy the undercloud, deploy the overcloud, and
# perform some validation tests on the overcloud.
- name: Install undercloud and deploy overcloud
hosts: undercloud
gather_facts: no
roles:
- tripleo/undercloud
- tripleo/overcloud

View File

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- tripleo-inventory