Use static IP on provisioning network to access the seed

This saves us some messing around with the dynamic libvirt IP address
and writing out the IP address to the Ansible inventory.
This commit is contained in:
Mark Goddard 2017-03-16 13:56:42 +00:00
parent 3ca08afd93
commit 52833cf481
10 changed files with 75 additions and 71 deletions

View File

@ -1,4 +1,11 @@
--- ---
###############################################################################
# Seed node configuration.
# User with which to access the seed via SSH during bootstrap, in order to
# setup the Kayobe user account.
seed_bootstrap_user: "{{ lookup('env', 'USER') }}"
############################################################################### ###############################################################################
# Seed node LVM configuration. # Seed node LVM configuration.

View File

@ -52,7 +52,3 @@ seed_vm_data_capacity: 100G
# Format of the seed VM data volume. # Format of the seed VM data volume.
seed_vm_data_format: qcow2 seed_vm_data_format: qcow2
# User with which to access the seed VM via SSH during bootstrap, in order to
# setup the Kayobe user account.
seed_vm_bootstrap_user: "{{ lookup('env', 'USER') }}"

View File

@ -1,3 +1,7 @@
--- ---
# User with which to access the controllers via SSH. # User with which to access the controllers via SSH.
ansible_user: "{{ kayobe_ansible_user }}" ansible_user: "{{ kayobe_ansible_user }}"
# User with which to access the controllers before the kayobe_ansible_user
# account has been created.
bootstrap_user: "{{ controller_bootstrap_user }}"

View File

@ -0,0 +1,3 @@
---
# Host/IP with which to access the seed via SSH.
ansible_host: "{{ provision_oc_net_name | net_ip }}"

View File

@ -1,3 +1,7 @@
--- ---
# User with which to access the seed VM via SSH. # User with which to access the seed via SSH.
ansible_user: "{{ kayobe_ansible_user }}" ansible_user: "{{ kayobe_ansible_user }}"
# User with which to access the seed before the kayobe_ansible_user account has
# been created.
bootstrap_user: "{{ seed_bootstrap_user }}"

View File

@ -2,13 +2,13 @@
- name: Ensure the Kayobe Ansible user account exists - name: Ensure the Kayobe Ansible user account exists
hosts: seed:controllers hosts: seed:controllers
vars: vars:
ansible_user: "{{ seed_vm_bootstrap_user if inventory_hostname in groups['seed'] else controller_bootstrap_user }}" ansible_user: "{{ bootstrap_user }}"
tasks: tasks:
- block:
- name: Ensure the Kayobe Ansible group exists - name: Ensure the Kayobe Ansible group exists
group: group:
name: "{{ kayobe_ansible_user }}" name: "{{ kayobe_ansible_user }}"
state: present state: present
become: True
- name: Ensure the Kayobe Ansible user account exists - name: Ensure the Kayobe Ansible user account exists
user: user:
@ -16,14 +16,12 @@
group: "{{ kayobe_ansible_user }}" group: "{{ kayobe_ansible_user }}"
comment: "Kayobe Ansible SSH access" comment: "Kayobe Ansible SSH access"
state: present state: present
become: True
- name: Ensure the Kayobe Ansible user has passwordless sudo - name: Ensure the Kayobe Ansible user has passwordless sudo
copy: copy:
content: "{{ kayobe_ansible_user }} ALL=(ALL) NOPASSWD: ALL" content: "{{ kayobe_ansible_user }} ALL=(ALL) NOPASSWD: ALL"
dest: "/etc/sudoers.d/kayobe-ansible-user" dest: "/etc/sudoers.d/kayobe-ansible-user"
mode: 0440 mode: 0440
become: True
- name: Ensure the Kayobe Ansible user has authorized our SSH key - name: Ensure the Kayobe Ansible user has authorized our SSH key
authorized_key: authorized_key:

View File

@ -4,12 +4,32 @@
vars: vars:
seed_host: "{{ groups['seed'][0] }}" seed_host: "{{ groups['seed'][0] }}"
seed_hostvars: "{{ hostvars[seed_host] }}" seed_hostvars: "{{ hostvars[seed_host] }}"
seed_user_data_path: "{{ image_cache_path }}/seed-vm-user-data"
pre_tasks: pre_tasks:
- name: Verify the seed host exists in the Ansible inventory
fail:
msg: >
There should be exactly one host in the seed group. There are
currently {{ groups['seed'] | length }}.
when: "{{ groups['seed'] | length != 1 }}"
- name: Ensure the image cache directory exists - name: Ensure the image cache directory exists
file: file:
path: "{{ image_cache_path }}" path: "{{ image_cache_path }}"
state: directory state: directory
# The user data script is used to bring up the network interfaces that will
# be configured by metadata in the configdrive. It could be used for other
# things in future if necessary.
- name: Ensure the user data file exists
copy:
content: |
#!/bin/bash
{% for interface in seed_hostvars.seed_vm_interfaces | map(attribute='net_name') | map('net_interface', seed_host) %}
ifup {{ interface }}
{% endfor %}
dest: "{{ seed_user_data_path }}"
roles: roles:
- role: jriguera.configdrive - role: jriguera.configdrive
# For now assume the VM OS family is the same as the hypervisor's. # For now assume the VM OS family is the same as the hypervisor's.
@ -30,6 +50,7 @@
map(attribute='net_name') | map(attribute='net_name') |
map('net_configdrive_network_device', seed_host) | map('net_configdrive_network_device', seed_host) |
list }} list }}
configdrive_config_user_data_path: "{{ seed_user_data_path }}"
tasks: tasks:
- name: Set a fact containing the configdrive image path - name: Set a fact containing the configdrive image path
@ -42,10 +63,13 @@
| gunzip | gunzip
> {{ seed_vm_configdrive_path }} > {{ seed_vm_configdrive_path }}
- name: Ensure compressed configdrive is removed - name: Ensure unnecessary files are removed
file: file:
path: "{{ image_cache_path }}/{{ seed_host | to_uuid }}.gz" path: "{{ item }}"
state: absent state: absent
with_items:
- "{{ seed_user_data_path }}"
- "{{ image_cache_path }}/{{ seed_host | to_uuid }}.gz"
- name: Ensure that the seed VM is provisioned - name: Ensure that the seed VM is provisioned
hosts: seed-hypervisor hosts: seed-hypervisor
@ -53,7 +77,7 @@
seed_host: "{{ groups['seed'][0] }}" seed_host: "{{ groups['seed'][0] }}"
seed_hostvars: "{{ hostvars[seed_host] }}" seed_hostvars: "{{ hostvars[seed_host] }}"
pre_tasks: pre_tasks:
- name: Check the size of the configdrive - name: Check the size of the configdrive image
stat: stat:
path: "{{ seed_vm_configdrive_path }}" path: "{{ seed_vm_configdrive_path }}"
register: stat_result register: stat_result
@ -77,44 +101,9 @@
become: True become: True
tasks: tasks:
- name: Check the seed VM's IP address
shell: virsh domifaddr {{ seed_vm_name }} | awk 'NR > 2 { print $4 }'
register: ifaddr_result
changed_when: False
become: True
until: "{{ ifaddr_result | failed or ifaddr_result.stdout != '' }}"
retries: 60
delay: 1
- name: Ensure the inventory contains a group variables directory for the seed
local_action:
module: file
path: "{{ item.path }}"
state: directory
become: "{{ item.become | bool }}"
with_items:
- { path: "{{ kayobe_config_path }}/inventory/group_vars/seed", become: False }
# Generate inventory group variable files for the seed VM. Note that this
# host will not be accessible to this instance of Ansible - another process
# should be started.
- name: Ensure the inventory contains a group variables file for the seed
local_action:
module: copy
content: |
---
# Do not edit this file - it is managed by Ansible and changes will be lost.
# Ansible inventory file for the Kayobe seed VM.
# This host will provide the Bifrost undercloud.
ansible_host: "{{ ifaddr_result.stdout_lines[0] | ipaddr('address') }}"
dest: "{{ item.path }}"
become: "{{ item.become | bool }}"
with_items:
- { path: "{{ kayobe_config_path }}/inventory/group_vars/seed/ansible-host", become: False }
- name: Wait for SSH access to the seed VM - name: Wait for SSH access to the seed VM
local_action: local_action:
module: wait_for module: wait_for
host: "{{ ifaddr_result.stdout_lines[0] | ipaddr('address') }}" host: "{{ seed_hostvars.ansible_host }}"
port: 22 port: 22
state: started state: started

View File

@ -29,10 +29,6 @@
# Base image for the seed VM root volume. # Base image for the seed VM root volume.
#seed_vm_root_image: #seed_vm_root_image:
# User with which to access the seed VM via SSH during bootstrap, in order to
# setup the Kayobe user account.
#seed_vm_bootstrap_user:
############################################################################### ###############################################################################
# Dummy variable to allow Ansible to accept this file. # Dummy variable to allow Ansible to accept this file.
workaround_ansible_issue_8743: yes workaround_ansible_issue_8743: yes

View File

@ -1,6 +1,11 @@
--- ---
###############################################################################
# Seed node configuration. # Seed node configuration.
# User with which to access the seed via SSH during bootstrap, in order to
# setup the Kayobe user account.
#seed_bootstrap_user:
############################################################################### ###############################################################################
# Network interface attachments. # Network interface attachments.

View File

@ -149,6 +149,8 @@ class SeedVMProvision(KollaAnsibleMixin, KayobeAnsibleMixin, Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.app.LOG.debug("Provisioning seed VM") self.app.LOG.debug("Provisioning seed VM")
ansible.run_playbook(parsed_args, "ansible/ip-allocation.yml",
limit="seed")
ansible.run_playbook(parsed_args, "ansible/seed-vm.yml") ansible.run_playbook(parsed_args, "ansible/seed-vm.yml")
# Now populate the Kolla Ansible inventory. # Now populate the Kolla Ansible inventory.
ansible.run_playbook(parsed_args, "ansible/kolla-ansible.yml", ansible.run_playbook(parsed_args, "ansible/kolla-ansible.yml",