-
Notifications
You must be signed in to change notification settings - Fork 16
/
prepare_undercloud.yml
79 lines (68 loc) · 1.95 KB
/
prepare_undercloud.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
---
- hosts: localhost
tasks:
- include_tasks: tasks/copykeys.yml
vars:
hostname: "{{ undercloud_hostname }}"
ssh_user: "root"
- name: add undercloud_host to inventory file
add_host:
name: "undercloud"
ansible_host: "{{ undercloud_hostname }}"
ansible_ssh_private_key_file: "{{ ansible_ssh_key }}"
ansible_user: "root"
ansible_python_interpreter: "{{ python_interpreter }}"
- hosts: undercloud
gather_facts: yes
tasks:
- name: Clean network interfaces
shell: |
/root/clean-interfaces.sh --nuke
changed_when: false
ignore_errors: true
- name: Ensure SELinux is set to enforcing mode
selinux:
policy: targeted
state: enforcing
- name: Reboot machine
shell: "nohup sh -c '( sleep 5 ; shutdown -r now )' &"
async: 0
poll: 0
changed_when: false
ignore_errors: true
- hosts: localhost
tasks:
- include_tasks: tasks/wait_after_node_reboot.yml
vars:
hypervisor_host: "{{ undercloud_hostname }}"
- hosts: undercloud
vars:
user: "stack"
gather_facts: yes
tasks:
- name: add stack user
user:
name: "{{ user }}"
password: "{{ ansible_ssh_pass }}"
create_home: yes
home: "/home/{{ user }}"
- name: copy public key
copy:
src: "~/.ssh/id_rsa.pub"
dest: "/root/ssh_keyfile"
- name: Add authorized keys
authorized_key:
user: "{{ user }}"
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
- name: Add to sudoers
lineinfile:
dest: "/etc/sudoers"
line: "{{ user }} ALL=(root) NOPASSWD:ALL"
- name: Check if ssh keys exists
stat:
path: "/home/{{ user }}/.ssh/id_rsa"
register: ssh_keys_result
- name: create ssh key pair
shell: |
ssh-keygen -q -t rsa -f /home/{{ user }}/.ssh/id_rsa -C "" -N ""
when: ssh_keys_result.stat.exists == False