-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0_prepare_cluster.yml
83 lines (68 loc) · 2.13 KB
/
0_prepare_cluster.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
---
# Prepares the cluster to be securely accessed by ansible controllers without password
# Creates an admin account in every cluster node
# File: 0_prepare_cluster.yml
- hosts: ansible-controllers
serial: 1
become: yes
become_user: root
vars_prompt:
- name: "admin_user"
prompt: "Enter username for the cluster administrator account:"
private: no
confirm: yes
- name: "admin_pass"
prompt: "Enter password for the cluster administrator account:"
private: yes
confirm: yes
encrypt: "sha256_crypt"
tasks:
- name: install/update epel-release
yum:
name: epel-release
state: latest
tags: epel
- name: install pip
yum:
name: python-pip
state: latest
tags: pip
- name: install pexpect
command: pip install pexpect
tags: pexpect
- name: create group 'clusteradmins'
group:
name: clusteradmins
state: present
delegate_to: "{{ item }}"
loop: "{{ groups['all'] }}"
- name: everyone in group 'clusteradmins' can sudo
lineinfile:
path: /etc/sudoers
regexp: '^%clusteradmins ALL=\(ALL\) ALL'
line: "%clusteradmins ALL=(ALL) ALL"
delegate_to: "{{ item }}"
loop: "{{ groups['all'] }}"
- name: create cluster administrator user in all hosts
user:
name: "{{ admin_user }}"
state: present
group: clusteradmins
password: "{{ admin_pass }}"
delegate_to: "{{ item }}"
loop: "{{ groups['all'] }}"
- name: generate ssh key
user:
name: "{{ admin_user }}"
generate_ssh_key: yes
ssh_key_file: /home/{{ admin_user }}/.ssh/id_rsa
ssh_key_comment: "{{ admin_user }} on {{ ansible_nodename }}"
register: user
- name: add key to authorized keys in hosts
authorized_key:
user: "{{ admin_user }}"
state: present
key: "{{ user.ssh_public_key }}"
delegate_to: "{{ item }}"
loop: "{{ groups['all'] }}"
...