Compare commits

6 Commits

9 changed files with 114 additions and 20 deletions
+7
View File
@@ -1,7 +1,14 @@
--- ---
all: all:
children: children:
this_host:
hosts:
localhost:
ansible_become_password: "{{ ansible_become_passwd }}"
ansible_connection: local
ansible_python_interpreter: "{{ ansible_playbook_python }}"
physical: physical:
hosts:
proxmox_1: proxmox_1:
ansible_host: "{{ proxmox_1_host }}" ansible_host: "{{ proxmox_1_host }}"
ansible_become_password: "{{ ansible_become_passwd }}" ansible_become_password: "{{ ansible_become_passwd }}"
-7
View File
@@ -1,7 +0,0 @@
---
physical:
hosts:
localhost:
ansible_become_password: "{{ ansible_become_passwd }}"
ansible_connection: local
ansible_python_interpreter: "{{ ansible_playbook_python }}"
@@ -1,6 +1,6 @@
--- ---
- name: Deploy LXC - name: Deploy LXC
hosts: all hosts: localhost
remote_user: ansible remote_user: ansible
gather_facts: false gather_facts: false
+34 -3
View File
@@ -1,6 +1,6 @@
--- ---
- name: Deploy VM - name: Deploy VM
hosts: all hosts: localhost
remote_user: ansible remote_user: ansible
gather_facts: false gather_facts: false
@@ -15,6 +15,16 @@
prompt: "Hostname for the VM (may only contain letters (a-z, A-Z), numbers (0-9), and hyphens)" prompt: "Hostname for the VM (may only contain letters (a-z, A-Z), numbers (0-9), and hyphens)"
private: false private: false
- name: vm_os_template
prompt: "Select OS template. Available: debian-13 | alpine"
default: "debian-13"
private: false
- name: vm_become_method
prompt: "Select become method. Available: sudo | su | pbrun | pfexec | doas | dzdo | ksu | runas | machinectl"
default: "sudo"
private: false
- name: vm_ip_address - name: vm_ip_address
prompt: "IP address for the VM (in x.x.x.x/x formant)" prompt: "IP address for the VM (in x.x.x.x/x formant)"
private: false private: false
@@ -28,15 +38,35 @@
when: not vm_hostname is regex('^[a-zA-Z0-9-]+$') when: not vm_hostname is regex('^[a-zA-Z0-9-]+$')
run_once: true run_once: true
- name: Validate OS template
ansible.builtin.fail:
msg: |
Invalid OS template: "{{ vm_os_template }}"
Select from available options: debian-13, alpine
when: vm_os_template not in ['debian-13', 'alpine']
run_once: true
- name: Validate become method
ansible.builtin.fail:
msg: |
Invalid become method: "{{ vm_become_method }}"
Select from available options: sudo | su | pbrun | pfexec | doas | dzdo | ksu | runas | machinectl
when: vm_become_method not in ['sudo', 'su', 'pbrun', 'pfexec', 'doas', 'dzdo', 'ksu', 'runas', 'machinectl']
run_once: true
roles: roles:
- ../roles/deploy_vm_on_proxmox - ../roles/deploy_vm_on_proxmox
tasks: tasks:
- name: Make the prompted hostname available to the whole playbook - name: Make the hostname available to the whole playbook
ansible.builtin.set_fact: ansible.builtin.set_fact:
fact_vm_hostname: "{{ vm_hostname }}" fact_vm_hostname: "{{ vm_hostname }}"
- name: Make the prompted IP available to the whole playbook - name: Make the OS template available to the whole playbook
ansible.builtin.set_fact:
fact_vm_os_template: "{{ vm_os_template }}"
- name: Make the IP available to the whole playbook
ansible.builtin.set_fact: ansible.builtin.set_fact:
fact_vm_ip_address: "{{ vm_ip_address.split('/') | first }}" fact_vm_ip_address: "{{ vm_ip_address.split('/') | first }}"
@@ -46,6 +76,7 @@
groups: new_host groups: new_host
ansible_user: ansible ansible_user: ansible
ansible_become_password: "{{ ansible_become_passwd }}" ansible_become_password: "{{ ansible_become_passwd }}"
ansible_become_method: "{{ vm_become_method }}"
- name: Configure VM - name: Configure VM
+1 -1
View File
@@ -1,5 +1,5 @@
--- ---
- name: Deploy and set up an LXC container in Proxmox - name: Perform regular maintenance
hosts: virtual hosts: virtual
remote_user: ansible remote_user: ansible
@@ -1,19 +1,63 @@
--- ---
- name: Generate locales - name: Generate locales for Debian-based systems
community.general.locale_gen: community.general.locale_gen:
name: name:
- en_US.UTF-8 - en_US.UTF-8
- ru_RU.UTF-8 - ru_RU.UTF-8
state: present state: present
when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu")
- name: Set locale - name: Set locale for Debian-based systems
ansible.builtin.copy: ansible.builtin.copy:
dest: /etc/locale.conf dest: /etc/locale.conf
mode: '0644' mode: '0644'
content: | content: |
LANG=en_US.UTF-8 LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8 LC_ALL=en_US.UTF-8
when: (ansible_facts['distribution'] == "Debian") or
(ansible_facts['distribution'] == "Ubuntu")
# The same for Alpine
- name: Install musl-locales package for Alpine
community.general.apk:
name: musl-locales
state: present
when: ansible_facts['distribution'] == "Alpine"
- name: Copy default locale profile to a custom override file for Alpine
ansible.builtin.copy:
src: /etc/profile.d/20locale.sh
dest: /etc/profile.d/locale.sh
remote_src: true
mode: '0644'
owner: root
group: root
force: false # Do not overwrite if the file already exists
when: ansible_facts['distribution'] == "Alpine"
- name: Set LANG and LC_ALL in the custom locale file for Alpine
ansible.builtin.lineinfile:
path: /etc/profile.d/locale.sh
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
loop:
- { regexp: '^export LANG=', line: 'export LANG=en_US.UTF-8' }
- { regexp: '^export LC_ALL=', line: 'export LC_ALL=en_US.UTF-8' }
when: ansible_facts['distribution'] == "Alpine"
- name: Ensure Unicode is enabled in /etc/rc.conf for Alpine
ansible.builtin.lineinfile:
path: /etc/rc.conf
regexp: '^#?unicode='
line: 'unicode="YES"'
state: present
when: ansible_facts['distribution'] == "Alpine"
# Works fine for all
- name: Set time - name: Set time
community.general.timezone: community.general.timezone:
name: Europe/Samara name: Europe/Samara
@@ -6,8 +6,9 @@ alpine_packages:
- git - git
- kitty - kitty
- neovim - neovim
- openssh
- openssh-server - openssh-server
- ranger - ranger
- rsync - rsync
- ssh - tzdata
- zsh - zsh
@@ -8,6 +8,18 @@
- sudo - sudo
update-cache: true update-cache: true
- name: Ensure /etc/resolv.conf exists with DNS servers
when: (ansible_facts['distribution'] == "Alpine")
ansible.builtin.copy:
dest: /etc/resolv.conf
content: |
nameserver 192.168.0.1
nameserver 8.8.8.8
mode: '0644'
owner: root
group: root
become: true
# The same commands for Alpine # The same commands for Alpine
- name: Update and install packages on Alpine - name: Update and install packages on Alpine
when: (ansible_facts['distribution'] == "Alpine") when: (ansible_facts['distribution'] == "Alpine")
@@ -24,6 +36,12 @@
name: sshusers name: sshusers
state: present state: present
- name: Ensure group "sudo" exists
ansible.builtin.group:
name: sudo
state: present
## Add the user to sshusers (for ssh access) and sudo (gain root access) ## Add the user to sshusers (for ssh access) and sudo (gain root access)
- name: Create a new user with a password for Ansible - name: Create a new user with a password for Ansible
ansible.builtin.user: ansible.builtin.user:
@@ -10,7 +10,7 @@
api_token_id: ansible api_token_id: ansible
api_token_secret: "{{ proxmox_token_secret }}" api_token_secret: "{{ proxmox_token_secret }}"
clone: debian-13-cloud-init-template clone: "{{ vm_os_template }}-cloud-init-template"
name: "{{ vm_hostname }}" name: "{{ vm_hostname }}"
storage: main storage: main
format: qcow2 format: qcow2