-
Notifications
You must be signed in to change notification settings - Fork 138
/
bootstrap-vcloud-nodes.yml
212 lines (188 loc) · 6.36 KB
/
bootstrap-vcloud-nodes.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#
# (c) Copyright 2018 SUSE LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
---
- import_playbook: _create-vcloud-inventory.yml
- name: Bootstrap virtual deployer for ardana
hosts: "{{ cloud_env }}"
remote_user: ardana
gather_facts: False
vars:
task: "deploy"
tasks:
- block:
- name: Create SSH keys for ardana and root (if needed) on deployer
become: yes
become_user: "{{ item_ssh_user }}"
command: >
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
args:
creates: "~/.ssh/id_rsa"
loop:
- ardana
- root
loop_control:
loop_var: item_ssh_user
- name: Get ardana and root user public keys
become: yes
become_user: "{{ item_ssh_user }}"
slurp:
src: "~/.ssh/id_rsa.pub"
register: ardana_pub_keys
loop:
- ardana
- root
loop_control:
loop_var: item_ssh_user
- name: Add ardana and root user public keys to authorized_keys
become: yes
become_user: "{{ item_ssh_user.user }}"
lineinfile:
path: "{{ item_ssh_user.path }}/.ssh/authorized_keys"
line: "{{ ardana_pub_keys.results | selectattr('item_ssh_user', 'equalto', item_ssh_user.user) | map(attribute='content') | list | first | b64decode }}"
state: present
create: yes
owner: "{{ item_ssh_user.user }}"
group: "{{ item_ssh_user.user }}"
mode: 0600
loop:
- { user: 'ardana', path: '/var/lib/ardana' }
- { user: 'root', path: '/root' }
loop_control:
loop_var: item_ssh_user
- name: Enable skip_disk_config on deployer
file:
state: "{{ item.state }}"
path: "{{ item.path }}"
loop:
- state: directory
path: "/etc/openstack"
- state: touch
path: "/etc/openstack/skip_disk_config"
become: yes
when: not want_lvm
rescue:
- include_role:
name: rocketchat_notify
vars:
rc_action: "finished"
rc_state: "Failed"
when: rc_notify
- name: Stop if something failed
fail:
msg: "{{ task }} failed."
- name: Bootstrap other virtual nodes for ardana
hosts: cloud_virt_hosts
any_errors_fatal: true
remote_user: root
# NOTE: don't gather facts before nodes become accessible
gather_facts: false
vars:
task: "deploy"
tasks:
- block:
# Do not use the wait_for_connection module here as it is not reliable when
# using mitogen through bastion hosts.
- name: Wait for cloud nodes to be accessible
delegate_to: localhost
wait_for:
host: "{{ ansible_ssh_host }}"
port: 22
search_regex: OpenSSH
state: started
delay: 10
register: _connection
- name: Fail if one or more hosts are unreacheable
fail:
when: hostvars[item]['_connection']['failed']
loop: "{{ ansible_play_hosts_all }}"
run_once: True
- name: Gather facts
setup:
- include_role:
name: setup_root_partition
- name: Create ardana group
group:
name: "ardana"
state: "present"
- name: Create ardana user
user:
name: "ardana"
group: "ardana"
comment: "Ardana Home"
shell: "/bin/bash"
createhome: yes
home: "/var/lib/ardana"
- name: Allow passwordless sudo for ardana user
lineinfile:
path: "/etc/sudoers.d/ardana"
line: "ardana ALL=(ALL) NOPASSWD: ALL"
state: present
create: yes
validate: "visudo -cf %s"
- name: Ensure .ssh directory
file:
state: directory
path: "/var/lib/ardana/.ssh"
owner: ardana
group: ardana
mode: 0700
- name: Add ardana and root user public keys to authorized_keys
lineinfile:
path: "{{ item_ssh_user.path }}/.ssh/authorized_keys"
line: "{{ hostvars[cloud_env].ardana_pub_keys.results | selectattr('item_ssh_user', 'equalto', item_ssh_user.user) | map(attribute='content') | list | first | b64decode }}"
state: present
create: yes
owner: "{{ item_ssh_user.user }}"
group: "{{ item_ssh_user.user }}"
mode: 0600
loop:
- { user: 'ardana', path: '/var/lib/ardana' }
- { user: 'root', path: '/root' }
loop_control:
loop_var: item_ssh_user
- include_role:
name: ssh_keys
become: yes
become_user: root
- name: Enable skip_disk_config on non-deployer nodes
file:
state: "{{ item.state }}"
path: "{{ item.path }}"
loop:
- state: directory
path: "/etc/openstack"
- state: touch
path: "/etc/openstack/skip_disk_config"
when: ansible_os_family == 'RedHat' or not want_lvm
- name: Add CentOS repository
yum_repository:
name: CentOS-Base
description: "CentOS Base Repository"
gpgcheck: no
baseurl: "http://{{ hostvars['localhost'].admin_conf_ip }}:79/ardana/rhel7/yum/OS"
when: ansible_os_family == 'RedHat'
rescue:
- include_role:
name: rocketchat_notify
apply:
delegate_to: "{{ cloud_env }}"
vars:
rc_action: "finished"
rc_state: "Failed"
when: rc_notify
- name: Stop if something failed
fail:
msg: "{{ task }} failed."