From 2def96a891eb046b2d91400d58843ac85564a6e8 Mon Sep 17 00:00:00 2001 From: ePietry Date: Thu, 28 Mar 2024 09:39:12 +0100 Subject: [PATCH] add gen & kickstart --- ansible/playbooks/gen_iso_image.yaml | 55 ++++++++++++++++++++++ ansible/playbooks/kickstart.yaml | 11 +++++ ansible/playbooks/ostree_construction.yaml | 43 ++++++++++------- 3 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 ansible/playbooks/gen_iso_image.yaml create mode 100644 ansible/playbooks/kickstart.yaml diff --git a/ansible/playbooks/gen_iso_image.yaml b/ansible/playbooks/gen_iso_image.yaml new file mode 100644 index 0000000..ab52ea8 --- /dev/null +++ b/ansible/playbooks/gen_iso_image.yaml @@ -0,0 +1,55 @@ +- name: Generate the Installer ISO image + hosts: all + vars_files: ../credentials.yaml + tasks: + - name: Clear /tmp/microshift_bluprint + ansible.builtin.file: + path: /tmp/microshift_bluprint.toml + state: absent + - name: Create /tmp/microshift_bluprint + ansible.builtin.file: + path: /tmp/microshift_bluprint.toml + state: file + mode: "0755" + - name: Write blueprint content to /tmp/microshift_bluprint file + ansible.builtin.copy: + dest: "/tmp/microshift_blueprint" + content: | + name = "microshift-installer" + + description = "" + version = "0.0.0" + modules = [] + groups = [] + packages = [] + become: true + + + - name: Push Blueprint + infra.osbuild.push_blueprint: + src: "/tmp/microshift_blueprint.toml" + + - name: Start the compose + ansible.builtin.shell: | + BUILDID=$(composer-cli compose start-ostree --url {{ repo_url }} --ref {{ ostree_ref }} {{ blueprint_name }} {{ compose_type }} | awk '{print $2}') + echo $BUILDID > /tmp/build_id + args: + executable: /bin/bash + register: start_compose_result + + - name: Wait for compose to finish (simplified example) + ansible.builtin.shell: | + BUILDID=$(cat /tmp/build_id) + until composer-cli compose status | grep -E "$BUILDID.*FINISHED"; do + sleep 30 + done + args: + executable: /bin/bash + + - name: Get BUILDID from file + ansible.builtin.shell: "cat /tmp/build_id" + register: build_id + + - name: Generate image from the compose + ansible.builtin.command: + cmd: "composer-cli compose image {{ build_id.stdout }}" diff --git a/ansible/playbooks/kickstart.yaml b/ansible/playbooks/kickstart.yaml new file mode 100644 index 0000000..9d16775 --- /dev/null +++ b/ansible/playbooks/kickstart.yaml @@ -0,0 +1,11 @@ +- name: creat kickstart + hosts: all + become: true + vars_files: ../config.yaml + tasks: + - name: set MICROSHIFT_PULL_SECRET + ansible.builtin.lineinfile: + path: "{{ ansible_env.HOME }}/red-hat-kiosk/imagebuilder/kiosk.ks" + regexp: '--url=http://__MYIP__/repo' + line: '--url=http://"{{ ansible_default_ipv4.address }}"' + backrefs: yes \ No newline at end of file diff --git a/ansible/playbooks/ostree_construction.yaml b/ansible/playbooks/ostree_construction.yaml index 2ba203e..e6cf946 100644 --- a/ansible/playbooks/ostree_construction.yaml +++ b/ansible/playbooks/ostree_construction.yaml @@ -5,20 +5,21 @@ - name: Solve dependencies for the blueprint ansible.builtin.command: composer-cli blueprints depsolve kiosk - - - name: Start ostree compose - infra.osbuild.start_compose: - blueprint: kiosk - compose_type: edge-commit - allow_duplicate: true - ostree_url: http://{{ ansible_default_ipv4.address }}/repo - register: builder_compose_start_out + - name: Start OSTree Compose + ansible.builtin.shell: + cmd: composer-cli compose start-ostree kiosk edge-commit --url http://{{ ansible_default_ipv4.address }}/repo --ref "rhel/9/{{ ansible_architecture }}/edge-kiosk" --parent "rhel/9/{{ ansible_architecture }}/edge" | awk '{print $2}' + register: build_id + + - name: Echo BuildID for Microshift Installer + ansible.builtin.debug: + msg: "Build {{ build_id.stdout_lines | first }} is running..." - name: Wait for compose to finish infra.osbuild.wait_compose: - compose_id: "{{ builder_compose_start_out['result']['body']['build_id'] }}" + compose_id: "{{build_id.stdout_lines | first}}" timeout: 3600 + - name: Create /tmp/commit repo ansible.builtin.file: path: /tmp/commit/ @@ -27,26 +28,31 @@ - name: Export the compose artifact to /tmp/commit infra.osbuild.export_compose: # noqa only-builtins - compose_id: "{{ builder_compose_start_out['result']['body']['build_id'] }}" - dest: /tmp/commit/{{ builder_compose_start_out['result']['body']['build_id'] }}.tar + compose_id: "{{ build_id.stdout_lines | first }}" + dest: /tmp/commit/{{ build_id.stdout_lines | first }}.tar - name: Create /tmp/commit/ID repo ansible.builtin.file: - path: /tmp/commit/{{ builder_compose_start_out['result']['body']['build_id'] }} + path: /tmp/commit/{{ build_id.stdout_lines | first }} mode: '0755' state: directory - - name: Extract compose artifact into /var/www/repo + - name: Extract compose artifact into /tmp/commit/ID ansible.builtin.unarchive: - src: /tmp/commit/{{ builder_compose_start_out['result']['body']['build_id'] }}.tar - dest: /tmp/commit/{{ builder_compose_start_out['result']['body']['build_id'] }} + src: /tmp/commit/{{ build_id.stdout_lines | first }}.tar + dest: /tmp/commit/{{ build_id.stdout_lines | first }} remote_src: true - name: Pull local ostree repository become: true - ansible.builtin.shell: ostree --repo=/var/www/repo pull-local "/tmp/commit/{{ builder_compose_start_out['result']['body']['build_id'] }}/repo" - + ansible.builtin.shell: ostree --repo=/var/www/repo pull-local "/tmp/commit/{{ build_id.stdout_lines | first }}/repo" + +# - name: Clear /tmp/commit repo +# ansible.builtin.file: +# path: /tmp/commit/ +# state: absent + - name: config ostree ref become: true ansible.builtin.shell: ostree --repo=/var/www/repo refs @@ -58,9 +64,10 @@ - name: config ostree logs kiosk become: true - ansible.builtin.shell: ostree --repo=/var/www/repo log rhel/9/x86_64/edge + ansible.builtin.shell: ostree --repo=/var/www/repo log rhel/9/{{ ansible_architecture }}/edge-kiosk register: logs - name: Print refs ansible.builtin.debug: var: logs.stdout_lines +