summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-08-11 00:33:30 +0200
committerAhmed Abdelhalim <[email protected]>2025-08-11 00:33:30 +0200
commit9612066c2431cc6a6e3e7ed558b464b0b1909ee2 (patch)
treeda6fb571a38c92ffcda0a4c5596d1b8ff1c3cc43
parent3cc7bb4b415e758786ed04d3b506031cd9f1971b (diff)
Add configure role on arch w/testing
-rw-r--r--molecule/default/converge.yml2
-rw-r--r--molecule/default/prepare.yml1
-rw-r--r--roles/bootstrap/README.md4
-rw-r--r--roles/configure/README.md20
-rw-r--r--roles/configure/meta/argument_specs.yml13
-rw-r--r--roles/configure/meta/main.yml14
-rw-r--r--roles/configure/tasks/install-archlinux.yml8
-rw-r--r--roles/configure/tasks/main.yml79
8 files changed, 140 insertions, 1 deletions
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
index b4ea57f..fe07d49 100644
--- a/molecule/default/converge.yml
+++ b/molecule/default/converge.yml
@@ -35,6 +35,7 @@
dev: "{{ partition_disk }}p3"
mount_path: "/mnt"
partition_extras: []
+ configure_playbook_dir: "../../../ansible-distro-configure"
pre_tasks:
- name: "Get test facts"
@@ -45,3 +46,4 @@
roles:
- role: partition
- role: bootstrap
+ - role: configure
diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml
index 371f7c3..e62ccab 100644
--- a/molecule/default/prepare.yml
+++ b/molecule/default/prepare.yml
@@ -14,7 +14,6 @@
path: "/opt/vdd.img"
size: 12G
mode: "0755"
- force: true
- name: "Create test_device (loop block device)"
become: true
diff --git a/roles/bootstrap/README.md b/roles/bootstrap/README.md
index c206179..bd75297 100644
--- a/roles/bootstrap/README.md
+++ b/roles/bootstrap/README.md
@@ -2,6 +2,10 @@
This role bootstraps the installation of a linux distro
+## Dependencies
+
+- Role: `partition`
+
## Role Variables
- `hostname` the distro linux network hostname to be used.
diff --git a/roles/configure/README.md b/roles/configure/README.md
new file mode 100644
index 0000000..dfab439
--- /dev/null
+++ b/roles/configure/README.md
@@ -0,0 +1,20 @@
+# Ansible Role: configure
+
+This role configures the bootstrapped distro installation basic networking functionality
+
+## Dependencies
+
+- Role: `bootstarp`
+
+## Role Variables
+
+- `configure_playbooks_path` the root directory of the distro-configure playbooks
+- `hostname` the hostname variable defined in bootstrap role
+- `mnt_root_path` the mount root path fact defined in bootstrap role
+
+## Internals
+
+- Install ansible on live environment
+- Copy `ansible-distro-configure` playbook (via archive because it's waaaay faster)
+- Update the `ansible-distro-configure` inventory to configure chroot (`mnt_root_path`)
+- Run the `ansible-distro-configure` playbook for desired `hostname`
diff --git a/roles/configure/meta/argument_specs.yml b/roles/configure/meta/argument_specs.yml
new file mode 100644
index 0000000..cd10572
--- /dev/null
+++ b/roles/configure/meta/argument_specs.yml
@@ -0,0 +1,13 @@
+---
+argument_specs:
+ main:
+ options:
+ configure_playbook_dir:
+ type: "str"
+ description: "The path to the configure playbook directory to run when provided"
+ hostname:
+ type: "str"
+ description: "Check hostname variable in role: bootstrap"
+ mnt_root_path:
+ type: "str"
+ description: "Check mnt_root_path fact in role: bootstrap"
diff --git a/roles/configure/meta/main.yml b/roles/configure/meta/main.yml
new file mode 100644
index 0000000..1599ace
--- /dev/null
+++ b/roles/configure/meta/main.yml
@@ -0,0 +1,14 @@
+---
+dependencies:
+ - bootstrap
+galaxy_info:
+ role_name: configure
+ author: a14m
+ description: "Configure the installed linux distro"
+ company: "kartoffeln.work GmbH."
+ license: "license MIT"
+ min_ansible_version: "2.18"
+ platforms:
+ - name: ArchLinux
+ versions:
+ - all
diff --git a/roles/configure/tasks/install-archlinux.yml b/roles/configure/tasks/install-archlinux.yml
new file mode 100644
index 0000000..d2f777f
--- /dev/null
+++ b/roles/configure/tasks/install-archlinux.yml
@@ -0,0 +1,8 @@
+---
+- name: "Ensure ansible dependencies are installed on live environment"
+ community.general.pacman:
+ name:
+ - "python3"
+ - "python-pip"
+ state: present
+ update_cache: true
diff --git a/roles/configure/tasks/main.yml b/roles/configure/tasks/main.yml
new file mode 100644
index 0000000..ba1f374
--- /dev/null
+++ b/roles/configure/tasks/main.yml
@@ -0,0 +1,79 @@
+---
+- name: "Install archlinux"
+ ansible.builtin.include_tasks: "install-archlinux.yml"
+ when: ansible_os_family == "Archlinux"
+
+- name: "Install ansible-core on live environment"
+ # Can't install ansible-core using package manager
+ # This resolve the "ERROR! ansible-galaxy requires resolvelib<1.1.1,>=0.5.3"
+ # where the python-resolvelib was updated but ansible package wasn't in the package managers
+ ansible.builtin.pip:
+ name: "ansible-core>=2.18"
+ state: "present"
+ break_system_packages: true
+
+- name: "Run distro-configure playbooks on bootstrapped distro"
+ when:
+ - configure_playbook_dir is defined
+ - mnt_root_path is defined
+ - hostname is defined
+ block:
+ - name: "Archive playbook on controller"
+ become: false
+ community.general.archive:
+ path: "{{ configure_playbook_dir }}/*"
+ dest: "/tmp/ansible-distro-configure.tar.gz"
+ mode: "0644"
+ format: "gz"
+ force_archive: true
+ exclude_path:
+ - "{{ configure_playbook_dir }}/.git"
+ - "{{ configure_playbook_dir }}/molecule"
+ delegate_to: localhost
+
+ - name: "Ensure playbook directory exists on live environment"
+ ansible.builtin.file:
+ path: "/opt/ansible-distro-configure"
+ state: "directory"
+ mode: "0750"
+
+ - name: "Unarchive playbook on live environment"
+ ansible.builtin.unarchive:
+ src: "/tmp/ansible-distro-configure.tar.gz"
+ dest: "/opt/ansible-distro-configure/"
+ list_files: false
+ remote_src: false
+
+ - name: "Update configure playbook inventory"
+ ansible.builtin.copy:
+ dest: "/opt/ansible-distro-configure/inventory/hosts.yml"
+ mode: "0640"
+ content: |
+ chroot:
+ vars:
+ ansible_user: "root"
+ ansible_connection: "chroot"
+ ansible_chroot_exe: "arch-chroot"
+ hosts:
+ {{ mnt_root_path }}:
+
+ - name: "Download playbook dependencies on live environment"
+ ansible.builtin.command:
+ cmd: "ansible-galaxy install -r /opt/ansible-distro-configure/requirements.yml"
+ changed_when: true
+
+ - name: "Run configure playbook using chroot connection"
+ ansible.builtin.command:
+ cmd: |
+ ansible-playbook site.yml
+ --limit "chroot"
+ --extra-vars '{"hostname":"{{ hostname }}"}'
+ --extra-vars "@/opt/ansible-distro-configure/host_vars/{{ hostname }}.yml"
+ --tags 'required_for_boot'
+ chdir: "/opt/ansible-distro-configure"
+ register: playbook
+ changed_when: true
+
+ - name: "Playbook stdout"
+ ansible.builtin.debug:
+ msg: "{{ playbook.stdout_lines }}"