infra/ansible/setup-proxmox-sudo.yml
2025-07-24 09:55:24 -05:00

46 lines
No EOL
1.1 KiB
YAML

---
# Setup passwordless sudo for ansible user on Proxmox hosts
# Run this with: ansible-playbook setup-proxmox-sudo.yml -e ansible_user=root
- name: Setup sudo for ansible user on Proxmox
hosts: proxmox
tasks:
- name: Ensure sudo is installed
apt:
name: sudo
state: present
update_cache: yes
- name: Ensure ansible user exists
user:
name: ansible
state: present
shell: /bin/bash
- name: Add ansible user to sudo group
user:
name: ansible
groups: sudo
append: yes
- name: Configure passwordless sudo for ansible user
lineinfile:
path: /etc/sudoers.d/ansible
line: 'ansible ALL=(ALL) NOPASSWD: ALL'
create: yes
mode: '0440'
validate: 'visudo -cf %s'
- name: Ensure .ssh directory exists for ansible user
file:
path: /home/ansible/.ssh
state: directory
owner: ansible
group: ansible
mode: '0700'
- name: Copy SSH key for ansible user
authorized_key:
user: ansible
key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"
state: present