REFACTOR: remove useless playbook, move creation of Ansible user into a separated role
This commit is contained in:
@@ -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') }}"
|
||||
@@ -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 }}"
|
||||
Reference in New Issue
Block a user