diff options
author | heqnx <root@heqnx.com> | 2025-06-22 21:37:01 +0300 |
---|---|---|
committer | heqnx <root@heqnx.com> | 2025-06-22 21:37:01 +0300 |
commit | a75493e62c8bd5f1daee90e7ee55bcd67b4b95b8 (patch) | |
tree | 3f0f0568529f22a9e429359035dc7f4ecdb92bc4 | |
parent | a6ec8f8947e1d6e56d1c0af6b67af2e7468ef98f (diff) | |
download | ansible-pve-host-a75493e62c8bd5f1daee90e7ee55bcd67b4b95b8.tar.gz ansible-pve-host-a75493e62c8bd5f1daee90e7ee55bcd67b4b95b8.zip |
added preflight, renamed tasks, added local non-pam user
-rw-r--r-- | main.yaml | 5 | ||||
-rw-r--r-- | tasks/preflight.yaml | 17 | ||||
-rw-r--r-- | tasks/pve_configure.yaml (renamed from tasks/configure_pve.yaml) | 34 | ||||
-rw-r--r-- | tasks/pve_setup.yaml (renamed from tasks/install_proxmox_on_debian12.yaml) | 17 |
4 files changed, 54 insertions, 19 deletions
@@ -4,5 +4,6 @@ vars_files: - vars/main.yaml tasks: - - import_tasks: tasks/install_proxmox_on_debian12.yaml - - import_tasks: tasks/configure_pve.yaml + - import_tasks: tasks/preflight.yaml + - import_tasks: tasks/pve_setup.yaml + - import_tasks: tasks/pve_configure.yaml diff --git a/tasks/preflight.yaml b/tasks/preflight.yaml new file mode 100644 index 0000000..aef9dcf --- /dev/null +++ b/tasks/preflight.yaml @@ -0,0 +1,17 @@ +- name: ensure script is run as root + ansible.builtin.assert: + that: + - ansible_effective_user_id == 0 + fail_msg: "this playbook must be run as root" + +- name: check if system is debian-based + ansible.builtin.command: dpkg -l + register: dpkg_check + changed_when: false + failed_when: false + +- name: fail if not debian-based + ansible.builtin.fail: + msg: "distribution not Debian-based" + when: dpkg_check.rc != 0 + diff --git a/tasks/configure_pve.yaml b/tasks/pve_configure.yaml index 73ef36f..c67be1a 100644 --- a/tasks/configure_pve.yaml +++ b/tasks/pve_configure.yaml @@ -53,3 +53,37 @@ state: restarted enabled: true when: ansible_service_mgr == 'systemd' + +- name: generate secure 32-character password + set_fact: + pve_admin_user: "pveadmin@pve" + pve_admin_group: "admin" + pve_admin_group_comment: "System Administrators" + pve_admin_password_file: "/root/pve_admin_password.txt" + pve_admin_password: "{{ lookup('password', '/dev/null length=32 chars=ascii_letters,digits') }}" + +- name: save password to file + copy: + content: "{{ pve_admin_password }}" + dest: "{{ pve_admin_password_file }}" + owner: root + group: root + mode: '0600' + +- name: create proxmox user + command: pveum useradd {{ pve_admin_user }} --password {{ pve_admin_password | quote }} + register: create_user + failed_when: create_user.rc != 0 + +- name: create proxmox admin group + command: pveum groupadd {{ pve_admin_group }} -comment "{{ pve_admin_group_comment }}" + register: create_group + failed_when: create_group.rc != 0 + +- name: assign administrator role to group + command: pveum aclmod / -group {{ pve_admin_group }} -role Administrator + register: assign_role + +- name: add user to admin group + command: pveum usermod {{ pve_admin_user }} -group {{ pve_admin_group }} + register: add_to_group diff --git a/tasks/install_proxmox_on_debian12.yaml b/tasks/pve_setup.yaml index 1a92aa5..7d04ff2 100644 --- a/tasks/install_proxmox_on_debian12.yaml +++ b/tasks/pve_setup.yaml @@ -1,20 +1,3 @@ -- name: ensure script is run as root - ansible.builtin.assert: - that: - - ansible_effective_user_id == 0 - fail_msg: "this playbook must be run as root" - -- name: check if system is debian-based - ansible.builtin.command: dpkg -l - register: dpkg_check - changed_when: false - failed_when: false - -- name: fail if not debian-based - ansible.builtin.fail: - msg: "distribution not Debian-based" - when: dpkg_check.rc != 0 - - name: generate /etc/hosts from template template: src: templates/hosts.j2 |