Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setup Ansible with Ansible
[defaults]
inventory = hosts
remote_user = username /*A current user on all systems that has sudo privileges*/
ask_pass = True
host_key_checking = False
ansible_port = 22
- name: Add Ansible user to all machines
hosts: servers
become: True
tasks:
- group:
name: ansible
gid: 2000
state: present
- user:
name: ansible
comment: "Ansible"
uid: 2000
group: ansible
groups: wheel
- name: Set authorized key took from file
authorized_key:
user: ansible
state: present
key: "{{ lookup('file', 'id-rsa.pub') }}"
- name: Allow 'wheel' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^# %wheel'
line: '%ansible ALL=(ALL) NOPASSWD: ALL'
[servers]
server01
server02
server03
server04
Run
> ansible-playbook --ask-become-pass ansible_user.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment