diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-08-11 00:33:30 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-08-11 00:33:30 +0200 |
| commit | 9612066c2431cc6a6e3e7ed558b464b0b1909ee2 (patch) | |
| tree | da6fb571a38c92ffcda0a4c5596d1b8ff1c3cc43 /roles | |
| parent | 3cc7bb4b415e758786ed04d3b506031cd9f1971b (diff) | |
Add configure role on arch w/testing
Diffstat (limited to 'roles')
| -rw-r--r-- | roles/bootstrap/README.md | 4 | ||||
| -rw-r--r-- | roles/configure/README.md | 20 | ||||
| -rw-r--r-- | roles/configure/meta/argument_specs.yml | 13 | ||||
| -rw-r--r-- | roles/configure/meta/main.yml | 14 | ||||
| -rw-r--r-- | roles/configure/tasks/install-archlinux.yml | 8 | ||||
| -rw-r--r-- | roles/configure/tasks/main.yml | 79 |
6 files changed, 138 insertions, 0 deletions
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 }}" |
