-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_inventory.yml
136 lines (124 loc) · 6.41 KB
/
update_inventory.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
- name: Update Inventory from OSPD
hosts: undercloud
gather_facts: yes
any_errors_fatal: true
vars:
user: heat-admin
# The var "private_key" is used outside this scope and cannot be overridden
overcloud_pkey: "{{ inventory_dir }}/id_rsa_overcloud"
tasks:
- name: fetch the private key file from the undercloud
fetch:
src: "~/.ssh/id_rsa"
dest: "{{ overcloud_pkey }}"
flat: yes
- name: update file permissions
delegate_to: localhost
become: no
file:
path: "{{ overcloud_pkey }}"
mode: 0600
- name: update IP of overcloud nodes
vars:
# Here can't be used {{ path_venv }}, because it's not a Jinja template
ansible_python_interpreter: "/var/tmp/venv_shade/bin/python"
os_server_facts:
cloud: undercloud
# Required for SSL
validate_certs: no
delegate_to: "{{ groups.shade | first }}"
# todo(obaranov) Remove hosts from the 'unused' group
# Currently ansible does not allow to remove existing host from a group
- name: add overcloud host
include_tasks: tasks/add_overcloud_host.yml
with_items: "{{ openstack_servers }}"
loop_control:
loop_var: node_info
- name: list ironic nodes
# Use CSV format as JSON not supported in old versions
shell: |
source ~/stackrc
openstack baremetal {{ 'node' if install.version|default(undercloud_version)|openstack_release >= 10 else '' }} list -f csv
register: ironic_node_list
tags: skip_ansible_lint
# Bug in Liberty version: No "node list" in openstack client, and no formatter in ironic client.
when: install.version|default(undercloud_version)|openstack_release != 8
# at this point we will have in inventory the openstack_node names
# and they are often not alligned with the bm names. For example,
# compute-2 OC node can correspond to the compute-1 bm node.
# node will be marked as unused only when original_name(bm) does not
# have instance uuid associated.
# also need to handle the situation when oc node name is changed
# (predictable hostnames and IPs feature)
# in that case controller-0 bm can be renamed to ctrl-0 OC.
# as the result the controller-0 node should be removed from the inventory
# (and not added to the unused group)
# and the ctrl-0 should be added with the original_name=controller-0
- name: set ironic nodes fact
vars:
# take ironic UUID if name is missing
- host_id: "{{ item.Name or item.UUID }}"
# original name points to the baremetal name
- host_original_name: "{{ hostvars.get(host_id, {}).original_name|default('') }}"
set_fact:
ironic_node_dict: "{{ ironic_node_dict|default({})|combine({ host_id: { 'original_name': host_original_name, 'instance_uuid': item['Instance UUID'] }}) }}"
# Set empty list for Liberty version
with_items: "{{ ironic_node_list.stdout|default('')|from_csv }}"
when: host_id in groups.all
- name: try to find unused nodes and add them into a new unused group
with_dict: "{{ ironic_node_dict|default({}) }}"
when:
- item.key not in openstack_servers|map(attribute='name')|list
- item.key in groups.all
- (ironic_node_dict|default({})).get(item.value.original_name|default(''), item.value).instance_uuid|default('undefined') == ''
add_host:
name: "{{ item.key }}"
# groups can only be added
groups: unused
# Connection for baremetals must be forwarded through UC as OC nodes
# lie on ctplane not accessible from anywhere else.
# Done as "redundant" block because Ansible can not reference
# one variable multiple times in block context.
- block:
- name: Enable SSH forwarding using UC node for baremetal OC nodes
vars:
ssh_user: "{{ hostvars[groups['undercloud'][0]].ansible_user|
default(hostvars[groups['undercloud'][0]].ansible_ssh_user) }}"
ssh_host: "{{ hostvars[groups['undercloud'][0]].ansible_host|
default(hostvars[groups['undercloud'][0]].ansible_ssh_host) }}"
add_host:
name: "{{ item.name }}"
ansible_ssh_common_args: "-o ProxyCommand=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-W %h:%p -i {{ hostvars[groups['undercloud'][0]].ansible_ssh_private_key_file }} \
{{ ssh_user }}@{{ ssh_host }}\""
when: "'hypervisor' not in groups"
with_items: "{{ openstack_servers }}"
- name: Enable SSH forwarding using hypervisor node for hybrid OC nodes
vars:
ssh_user: "{{ hostvars['hypervisor'].ansible_user|
default(hostvars['hypervisor'].ansible_ssh_user) }}"
ssh_host: "{{ hostvars['hypervisor'].ansible_host|
default(hostvars['hypervisor'].ansible_ssh_host) }}"
add_host:
name: "{{ item.name }}"
ansible_ssh_common_args: " -o ForwardAgent=yes -o ServerAliveInterval=30 -o ControlMaster=auto -o ControlPersist=30m -o StrictHostKeyChecking=no \
-o BatchMode=yes \
-o UserKnownHostsFile=/dev/null -o ProxyCommand=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-W %h:%p -i {{ hostvars[groups['undercloud'][0]].ansible_ssh_private_key_file }} \
{{ ssh_user }}@{{ ssh_host }}\""
when:
- "'hypervisor' in groups"
- install.hybrid|default(false)
with_items: "{{ openstack_servers }}"
- name: Update the inventory file
hosts: localhost
gather_facts: no
roles:
- role: inventory-update
omit_groups: [ 'ovb' ]
inventory_file_name: 'hosts-install'
omit_hosts: "{{ hostvars[groups['undercloud'][0]].nodes_to_delete|default([])|difference(hostvars[groups['undercloud'][0]].nodes_added|default([]))|difference(groups.get('unused', [])) }}"
tasks:
- name: refresh dynamic inventory
meta: refresh_inventory