Skip to content

Instantly share code, notes, and snippets.

@kguay
Last active February 28, 2023 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kguay/7c3122aedb1b19eba69fc3fbe5c420de to your computer and use it in GitHub Desktop.
Save kguay/7c3122aedb1b19eba69fc3fbe5c420de to your computer and use it in GitHub Desktop.
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