Skip to content

Instantly share code, notes, and snippets.

@maprangzth
Created October 22, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maprangzth/91191963c77fae33580d62a843e1f701 to your computer and use it in GitHub Desktop.
Save maprangzth/91191963c77fae33580d62a843e1f701 to your computer and use it in GitHub Desktop.
Simple Playbooks for Create User
---
- name: Create Ansible user
hosts: all
remote_user: root
vars:
user_name: maprangzth
user_keys: https://github.com/maprangzth.keys
tasks:
- name: Ensure ansible user exists
user:
name: "{{ user_name }}"
state: present
comment: "Ansible user"
- name: Ensure ansible user accepts the SSH key
authorized_key:
user: "{{ user_name }}"
key: "{{ user_keys }}"
validate_certs: False
state: present
- name: Ensure sudo package is installed (RHEL Base)
yum:
name: sudo
state: present
when: ansible_os_family == 'RedHat'
- name: Ensure sudo package is installed (Debian Base)
apt:
name: sudo
state: present
when: ansible_os_family == 'Debian'
- name: Ensure the ansible user is sudoer with no password required
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^{{ user_name }} ALL\='
line: '{{ user_name }} ALL=(ALL) NOPASSWD:ALL'
validate: 'visudo -cf %s'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment