forked from shiv123456789/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusercreate_prompt.yml
97 lines (73 loc) · 2.31 KB
/
usercreate_prompt.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
create ssh user in remote linux servers with user/password/auth_key promt
#######
# Create user
- hosts: "serverip or instance tag"
vars_prompt:
- name: "SSH_USER"
prompt: "User name for server"
# - name: "SSH_USER_PASSWORD"
# prompt: "Password for ssh user"
# private: yes
# encrypt: "sha512_crypt"
# confirm: yes
# no_log: true
- name: "AUTH_KEY"
prompt: "user auth key"
remote_user: ubuntu
sudo: yes
tasks:
- name: "Create ssh user"
user: name={{ SSH_USER }}
shell=/bin/bash
groups=
- name: "Add remote authorized key"
authorized_key: user={{ SSH_USER }} key={{ AUTH_KEY }}
- name: Allow sudo privilages
lineinfile:
dest: /etc/sudoers
state: present
line: '{{ Name }} ALL=(ALL) NOPASSWD:ALL'
validate: 'visudo -cf %s'
######
in above example ansible prompt you to input username that u want to create on server.
above yml is example of keybased ssh user, it will prompt to input the users ssh public key
- 1. if you want to create user with password than uncomment the
# - name: "SSH_USER_PASSWORD"
# prompt: "Password for ssh user"
# private: yes
# encrypt: "sha512_crypt"
# confirm: yes
# no_log: true
2. and comment the belwo lines
- name: "AUTH_KEY"
prompt: "user auth key"
- name: "Add remote authorized key"
authorized_key: user={{ SSH_USER }} key={{ AUTH_KEY }}
3.put the below line in tasks section below user name
password={{ ANSIBLE_USER_PASSWORD }}
Now password based user generation yml looks like
#######
# Create user
- hosts: "serverip or instance tag"
vars_prompt:
- name: "SSH_USER"
prompt: "User name for server"
- name: "SSH_USER_PASSWORD"
prompt: "Password for ssh user"
private: yes
encrypt: "sha512_crypt"
confirm: yes
no_log: true
# - name: "AUTH_KEY"
# prompt: "user auth key"
remote_user: ubuntu
sudo: yes
tasks:
- name: "Create ssh user"
user: name={{ SSH_USER }}
password={{ SSH_USER_PASSWORD }}
shell=/bin/bash
groups=
# - name: "Add remote authorized key"
# authorized_key: user={{ SSH_USER }} key={{ AUTH_KEY }}
######