From cb4d82c7cf9b9ad2c9887ea0b4ca4adf62bb4c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20L=C3=BCscher?= Date: Fri, 3 May 2024 14:21:06 +0000 Subject: [PATCH] feat(ansible): allow for input variable files to configure forge behavior (#13) --- ansible/group_vars/all.yml | 10 ---------- ansible/group_vars/all/data.yml | 4 ++++ ansible/group_vars/all/git.yml | 5 +++++ ansible/group_vars/all/registry.yml | 3 +++ ansible/host_vars/host.ublue.local.yml | 2 -- ansible/host_vars/localhost.yml | 2 ++ ansible/playbooks/configure_host.yml | 23 +++++++++++++++++++++++ ansible/playbooks/project_build.yml | 16 ++++++++++++++-- ansible/playbooks/project_clone.yml | 9 +++++++++ 9 files changed, 60 insertions(+), 14 deletions(-) delete mode 100644 ansible/group_vars/all.yml create mode 100644 ansible/group_vars/all/data.yml create mode 100644 ansible/group_vars/all/git.yml create mode 100644 ansible/group_vars/all/registry.yml delete mode 100644 ansible/host_vars/host.ublue.local.yml diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml deleted file mode 100644 index 912fbf4..0000000 --- a/ansible/group_vars/all.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -# variables used for all groups and hosts - -## container registry -forge_registry_url: registry.ublue.local - -## Git -forge_git_repository_url: https://github.com/ublue-os/bluefin.git -forge_git_repository_destination: "{{ ansible_facts.env.HOME }}/ublue-os/forge/bluefin" -forge_git_repository_version: main diff --git a/ansible/group_vars/all/data.yml b/ansible/group_vars/all/data.yml new file mode 100644 index 0000000..c01d5a2 --- /dev/null +++ b/ansible/group_vars/all/data.yml @@ -0,0 +1,4 @@ +--- +# data variables +forge_data_path: "{{ lookup('ansible.builtin.env', 'FORGE_DATA_PATH', default=ansible_facts.env.HOME + '/ublue-os_forge') }}" +forge_data_default_variables_file_path: "{{ forge_data_path }}/forge_default_vars.env" diff --git a/ansible/group_vars/all/git.yml b/ansible/group_vars/all/git.yml new file mode 100644 index 0000000..3ccb118 --- /dev/null +++ b/ansible/group_vars/all/git.yml @@ -0,0 +1,5 @@ +--- +# git variables +forge_git_repository_url: "{{ lookup('ansible.builtin.env', 'FORGE_GIT_REPOSITORY_URL', default='https://github.com/ublue-os/bluefin.git') }}" +forge_git_repository_destination: "{{ lookup('ansible.builtin.env', 'FORGE_GIT_REPOSITORY_DESTINATION', default=forge_data_path + '/bluefin') }}" +forge_git_repository_version: "{{ lookup('ansible.builtin.env', 'FORGE_GIT_REPOSITORY_VERSION', default='main') }}" diff --git a/ansible/group_vars/all/registry.yml b/ansible/group_vars/all/registry.yml new file mode 100644 index 0000000..66fcfaf --- /dev/null +++ b/ansible/group_vars/all/registry.yml @@ -0,0 +1,3 @@ +--- +# container registry variables +forge_registry_url: "{{ lookup('ansible.builtin.env', 'FORGE_REGISTRY_URL', default='registry.ublue.local') }}" diff --git a/ansible/host_vars/host.ublue.local.yml b/ansible/host_vars/host.ublue.local.yml deleted file mode 100644 index 361ccd7..0000000 --- a/ansible/host_vars/host.ublue.local.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# variables used in playbooks with target host.ublue.local diff --git a/ansible/host_vars/localhost.yml b/ansible/host_vars/localhost.yml index e187c8f..72af712 100644 --- a/ansible/host_vars/localhost.yml +++ b/ansible/host_vars/localhost.yml @@ -1,2 +1,4 @@ +--- +# localhost variables ansible_connection: local ansible_python_interpreter: "{{ ansible_playbook_python }}" diff --git a/ansible/playbooks/configure_host.yml b/ansible/playbooks/configure_host.yml index 25fb8bd..aefd887 100644 --- a/ansible/playbooks/configure_host.yml +++ b/ansible/playbooks/configure_host.yml @@ -24,3 +24,26 @@ cmd: update-ca-trust changed_when: false become: true + + - name: Create default directory for forge content + ansible.builtin.file: + path: "{{ forge_data_path }}" + state: directory + mode: "0755" + + - name: Create default configuration variable file + ansible.builtin.copy: + dest: "{{ forge_data_default_variables_file_path }}" + content: | + ## ublue-os forge configuration variables defaults + ## For more details got to https://github.com/ublue-os/forge/blob/main/docs/variables.md + + {% for item in __vars_used %} + #{{ item | upper }}={{ lookup('ansible.builtin.vars', item) }} + {% endfor %} + backup: true + owner: "{{ ansible_facts.env.USER }}" + mode: "0644" + vars: + __vars_used: "{{ lookup('ansible.builtin.varnames', __regex_search, wantlist=true) }}" + __regex_search: ^forge_.+ diff --git a/ansible/playbooks/project_build.yml b/ansible/playbooks/project_build.yml index 8e790ca..cd76580 100644 --- a/ansible/playbooks/project_build.yml +++ b/ansible/playbooks/project_build.yml @@ -2,10 +2,15 @@ - name: Build project hosts: host.ublue.local gather_facts: true + pre_tasks: + - name: DEBUG - forge variables + ansible.builtin.include_role: + name: debug_forge_vars + tasks: - - name: Build and push an image to registry + - name: Build and push image to registry containers.podman.podman_image: - name: bluefin + name: "{{ forge_git_repository_url | regex_search(__regex_search) }}" tag: latest path: "{{ forge_git_repository_destination }}" build: @@ -15,3 +20,10 @@ push: true push_args: dest: "{{ forge_registry_url }}" + vars: + __regex_search: (?<=/)[^/]+(?=\.git) + register: __podman_image_info + + - name: INFO | Status from build and push + ansible.builtin.debug: + msg: "{{ __podman_image_info }}" diff --git a/ansible/playbooks/project_clone.yml b/ansible/playbooks/project_clone.yml index 66e99fb..36bf457 100644 --- a/ansible/playbooks/project_clone.yml +++ b/ansible/playbooks/project_clone.yml @@ -2,9 +2,18 @@ - name: Clone project hosts: host.ublue.local gather_facts: true + pre_tasks: + - name: DEBUG - forge variables + ansible.builtin.include_role: + name: debug_forge_vars tasks: - name: Clone project ansible.builtin.git: repo: "{{ forge_git_repository_url }}" dest: "{{ forge_git_repository_destination }}" version: "{{ forge_git_repository_version }}" + register: __git_clone_info + + - name: INFO | Status from git clone + ansible.builtin.debug: + msg: "{{ __git_clone_info }}"