forked from MithunTechnologiesDevOps/AnisblePlayBooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible-createuser.yml
37 lines (37 loc) · 1.1 KB
/
ansible-createuser.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
# ansible <group/host Name> -m ping -u <userName> --private-key=~/devops.pem
# ansible-playbook -b ansible-createuser.yml -u <userName> --private-key=~/devops.pem
- hosts: all
tasks:
- name: Create Ansible User
user:
name: ansible
create_home: true
shell: /bin/bash
comment: "Ansible Management Account"
expires: -1
password: "{{ 'DevOps@2020' | password_hash('sha512','A512') }}"
- name: Deploy Local User SSH Key
authorized_key:
user: ansible
state: present
manage_dir: true
key: "{{ lookup('file', '/home/ansible/.ssh/id_rsa.pub') }}"
- name: Setup Sudo Access for Ansible User
copy:
dest: /etc/sudoers.d/ansible
content: 'ansible ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s
- name: Disable Password Authentication
lineinfile:
dest=/etc/ssh/sshd_config
regexp='^PasswordAuthentication'
line="PasswordAuthentication no"
state=present
backup=yes
notify:
- restart ssh
handlers:
- name: restart ssh
service:
name=sshd
state=restarted