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/configure/tasks | |
| parent | 3cc7bb4b415e758786ed04d3b506031cd9f1971b (diff) | |
Add configure role on arch w/testing
Diffstat (limited to 'roles/configure/tasks')
| -rw-r--r-- | roles/configure/tasks/install-archlinux.yml | 8 | ||||
| -rw-r--r-- | roles/configure/tasks/main.yml | 79 |
2 files changed, 87 insertions, 0 deletions
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 }}" |
