From f5670addc658fb955711bc5df264b47c7275754d Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Sun, 9 Aug 2026 17:27:42 +0400 Subject: [PATCH] REFACTOR: remove useless playbook, move creation of Ansible user into a separated role --- playbooks/deploy_lxc.yaml | 17 -------- roles/configure_ansible_user/tasks/main.yaml | 41 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 17 deletions(-) delete mode 100644 playbooks/deploy_lxc.yaml create mode 100644 roles/configure_ansible_user/tasks/main.yaml diff --git a/playbooks/deploy_lxc.yaml b/playbooks/deploy_lxc.yaml deleted file mode 100644 index b492713..0000000 --- a/playbooks/deploy_lxc.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Deplot simple test LXC on Proxmox VE - hosts: localhost - gather_facts: false - roles: - - ../roles/basic_proxmox_lxc - -- name: Basic Proxmox guest deployment - hosts: all - remote_user: root - roles: - - ../roles/basic_postinstall - vars_files: - ../inventory/group_vars/all/secrets.yaml - vars: - ansible_user_passwd_hash: "{{ ansible_password | password_hash('sha512', 's3edscrj45e6r') }}" - user_passwd_hash: "{{ user_password | password_hash('sha512', 's3ed6123jhgcr') }}" \ No newline at end of file diff --git a/roles/configure_ansible_user/tasks/main.yaml b/roles/configure_ansible_user/tasks/main.yaml new file mode 100644 index 0000000..2097ae9 --- /dev/null +++ b/roles/configure_ansible_user/tasks/main.yaml @@ -0,0 +1,41 @@ +--- +## Installing packages +- name: Install sudo on apt systems + when: (ansible_facts['distribution'] == "Debian") or + (ansible_facts['distribution'] == "Ubuntu") + ansible.builtin.apt: + name: + - sudo + update-cache: true + +# The same commands for Alpine +- name: Update and install packages on Alpine + when: (ansible_facts['distribution'] == "Alpine") + community.general.apk: + name: sudo + update_cache: true + remote_user: ansible + + +## Creating and setting up the ansible user +## First, create sshusers group to grant ssh access +- name: Ensure group "sshusers" exists + ansible.builtin.group: + name: sshusers + state: present + +## Add the user to sshusers (for ssh access) and sudo (gain root access) +- name: Create a new user with a password for Ansible + ansible.builtin.user: + name: ansible + password: "{{ ansible_user_passwd_hash }}" + + groups: sshusers,sudo + append: true + +## Since password authentication in SSH will be disabled, we need to add an authorized key +- name: Set authorized key taken from file + ansible.posix.authorized_key: + user: ansible + state: present + key: "{{ ansible_ssh_key }}"