infra/home/ansible/bootstrap-almalinux.yml
2025-09-06 12:46:26 -05:00

72 lines
No EOL
1.8 KiB
YAML

---
- name: Bootstrap AlmaLinux server for Ansible management
hosts: caddy
become: yes
vars:
ansible_user: graham # Connect as graham initially
tasks:
- name: Create ansible user
user:
name: ansible
uid: 10001
shell: /bin/bash
home: /home/ansible
create_home: yes
state: present
- name: Add ansible user to wheel group
user:
name: ansible
groups: wheel
append: yes
- name: Ensure .ssh directory exists for ansible user
file:
path: /home/ansible/.ssh
state: directory
owner: ansible
group: ansible
mode: "0700"
- name: Add ansible SSH key to ansible user
authorized_key:
user: ansible
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFghGMnDdkfNC6JPEhMxrKhYDmNcXjHXp/y/mf3uLtzb graham@mbp14.local"
state: present
- name: Add SSH keys from GitHub to graham user
authorized_key:
user: graham
key: "https://github.com/gmcintire.keys"
state: present
- name: Configure passwordless sudo for ansible user
copy:
content: "ansible ALL=(ALL) NOPASSWD: ALL"
dest: /etc/sudoers.d/ansible
mode: "0440"
validate: "visudo -cf %s"
- name: Install Python 3 (required for Ansible)
dnf:
name:
- python3
- python3-pip
state: present
- name: Set Python 3 as default python
alternatives:
name: python
link: /usr/bin/python
path: /usr/bin/python3
- name: Verify ansible user can sudo
command: sudo -u ansible sudo -l
changed_when: false
register: sudo_test
- name: Show sudo verification
debug:
msg: "Ansible user sudo access verified"
when: sudo_test.rc == 0