This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
/
inventory.yml
170 lines (149 loc) · 6.34 KB
/
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
- 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: '{{ overcloud_key }}'
flat: true
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 }}'
inventory_ip: '{{ item.value }}'
ansible_user: "{{ overcloud_user | default('heat-admin') }}"
ansible_private_key_file: "{{ overcloud_key }}"
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.ansible"'
- when: inventory == 'multinode'
block:
- name: Get subnodes
command: cat /etc/nodepool/sub_nodes_private
register: nodes
- name: Add subnode to ansible inventory
with_indexed_items: '{{ nodes.stdout_lines | default([]) }}'
add_host:
name: 'subnode-{{ item.0 + 2 }}'
groups: "overcloud"
ansible_host: '{{ item.1 }}'
inventory_ip: '{{ item.1 }}'
ansible_user: "{{ lookup('env','USER') }}"
ansible_private_key_file: "/etc/nodepool/id_rsa"
# required for regeneration of ssh.config.ansible
- name: set_fact for undercloud ip
set_fact:
undercloud_ip: "{{ hostvars['undercloud'].undercloud_ip }}"
cacheable: true
when: hostvars['undercloud'] is defined and hostvars['undercloud'].undercloud_ip is defined
- name: set_fact for virthost
set_fact:
virthost_with_private_key: "{{ 'virthost' in groups and groups['virthost']|length>0 and hostvars[groups['virthost'][0]].ansible_private_key_file is defined }}"
# Add the supplemental to the in-memory inventory.
- name: Add supplemental node vm to inventory
add_host:
name: supplemental
groups: supplemental
ansible_host: supplemental
ansible_fqdn: supplemental
ansible_user: '{{ supplemental_user }}'
ansible_private_key_file: '{{ local_working_dir }}/id_rsa_supplemental'
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.ansible"'
supplemental_node_ip: "{{ supplemental_node_ip }}"
when: supplemental_node_ip is defined
- name: set_fact for supplemental ip
set_fact:
supplemental_node_ip: "{{ hostvars['supplemental'].supplemental_node_ip }}"
cacheable: true
when: hostvars['supplemental'] is defined and hostvars['supplemental'].supplemental_node_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
ansible_host: '{{ undercloud_ip }}'
ansible_fqdn: undercloud
ansible_user: '{{ undercloud_user }}'
ansible_private_key_file: '{{ undercloud_key }}'
ansible_ssh_extra_args: '-F "{{ local_working_dir }}/ssh.config.local.ansible"'
undercloud_ip: "{{ undercloud_ip }}"
when: not virthost_with_private_key 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 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ hostvars[groups['virthost'][0]].ansible_private_key_file }}
{{ ssh_user }}@{{ hostvars[groups['virthost'][0]].ansible_host }}
-W {{ undercloud_ip }}:22"
cacheable: true
when: virthost_with_private_key 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 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ local_working_dir }}/id_rsa_virt_power
{{ ssh_user }}@{{ hostvars['localhost'].ansible_default_ipv4.address }}
-W {{ undercloud_ip }}:22"
cacheable: true
when: not virthost_with_private_key and undercloud_ip is defined
- name: set supplemental ssh proxy command
set_fact:
supplemental_ssh_proxy_command: "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
-o ConnectTimeout=60 -i {{ local_working_dir }}/id_rsa_virt_power
{{ ssh_user }}@{{ hostvars[groups['virthost'][0]].ansible_host }}
-W {{ supplemental_node_ip }}:22"
cacheable: true
when: supplemental_node_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: 0644
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: 0644
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
cacheable: true
when: undercloud_ip is not defined and result_stat_id_rsa_virt_power.stat.exists
- 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: 0644
when: undercloud_ip is not defined