Created
October 22, 2017 06:32
-
-
Save maprangzth/91191963c77fae33580d62a843e1f701 to your computer and use it in GitHub Desktop.
Simple Playbooks for Create User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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