Skip to content

Instantly share code, notes, and snippets.

@naavveenn
Created October 25, 2018 07:19
Show Gist options
  • Save naavveenn/4179f97aff2d66cb613f44040145fdb6 to your computer and use it in GitHub Desktop.
Save naavveenn/4179f97aff2d66cb613f44040145fdb6 to your computer and use it in GitHub Desktop.
---
##Creating multipple users##
- hosts: test
become: yes
gather_facts: no
vars_prompt:
- name: pass
prompt: "Please enter the password"
tasks:
- name: Creating users
user:
name: "{{ item }}"
password: "{{ pass | password_hash('sha512') }}"
shell: /bin/bash
generate_ssh_key: yes
with_items:
- user1
- user2
- user3
- name: Making entry of your ssh public key in authorized_keys file for all the users
authorized_key:
user: "{{ item }}"
key: "{{ lookup('file', '/home/ansible/.ssh/id_rsa.pub') }}"
state: present
with_items:
- user1
- user2
- name: Disable Password Authentication
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^PasswordAuthentication'
line: "PasswordAuthentication no"
state: present
backup: yes
notify:
- restart ssh
- name: Disable Root Login
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^PermitRootLogin'
line: "PermitRootLogin no"
state: present
backup: yes
notify:
- restart ssh
handlers:
- name: restart ssh
service:
name: sshd
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment