Last active
February 28, 2023 13:04
-
-
Save kguay/7c3122aedb1b19eba69fc3fbe5c420de to your computer and use it in GitHub Desktop.
Setup Ansible with Ansible
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
[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 |
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: 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' |
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
[servers] | |
server01 | |
server02 | |
server03 | |
server04 |
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
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