From e3f0f51aaaf2cc46c9c7f20bbb15880b4185b87d Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 24 Mar 2025 15:51:32 +0100 Subject: [PATCH 1/4] feat: Allow overriding distribution package name --- CHANGELOG.md | 4 ++++ defaults/main/main.yml | 15 +++++++++------ molecule/distribution/converge.yml | 6 ++++++ tasks/opensource/install-distribution.yml | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c6ccaa5..bc44b38d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.25.1 (Unreleased) +FEATURES: + +- Add a parameter, `nginx_distribution_package`, to override the default NGINX package when installing NGINX from your distribution/OS repository. + BUG FIXES: - Fix Ansible and Jinja versions validation tasks in ansible check mode. diff --git a/defaults/main/main.yml b/defaults/main/main.yml index 6ec521c08..bf29eff0e 100644 --- a/defaults/main/main.yml +++ b/defaults/main/main.yml @@ -46,6 +46,11 @@ nginx_manage_repo: true # Default is nginx_repository. nginx_install_from: nginx_repository +# (Optional) Specify repository for NGINX Open Source or NGINX Plus. +# Only works if 'install_from' is set to 'nginx_repository' when installing NGINX Open Source. +# Defaults are the official NGINX repositories. +# nginx_repository: deb https://nginx.org/packages/mainline/debian/ buster nginx + # Specify source install options for NGINX Open Source. # Options represent whether to install from source also or to install from packages (default). # These only apply if 'nginx_install_from' is set to 'source'. @@ -57,22 +62,20 @@ nginx_install_source_pcre: false nginx_install_source_openssl: true nginx_install_source_zlib: false -# Specify source install module for NGINX Open Source. +# Specify source install modules for NGINX Open Source. # You can select any of the static modules listed on http://nginx.org/en/docs/configure.html. # Format is '--with-*' where '*' should be used as static module name in the list below. (see an example below). # Default is 'http_ssl_module'. (DO NOT remove it if you need SSL support). nginx_static_modules: [http_ssl_module] # nginx_static_modules: ['http_v2_module'] # Example for '--with-http_v2_module' +# (Optional) Specify NGINX package name when installing nginx from an 'os_repository'. +# nginx_distribution_package: @nginx:1.24/common + # (Optional) Choose where to fetch the NGINX signing key from. # Default is the official NGINX signing key host. # nginx_signing_key: http://nginx.org/keys/nginx_signing.key -# (Optional) Specify repository for NGINX Open Source or NGINX Plus. -# Only works if 'install_from' is set to 'nginx_repository' when installing NGINX Open Source. -# Defaults are the official NGINX repositories. -# nginx_repository: deb https://nginx.org/packages/mainline/debian/ buster nginx - # Specify which branch of NGINX Open Source you want to install. # Options are 'mainline' or 'stable'. # Only works if 'install_from' is set to 'nginx_repository' or 'source'. diff --git a/molecule/distribution/converge.yml b/molecule/distribution/converge.yml index f0b0c0d95..1d43a6c9e 100644 --- a/molecule/distribution/converge.yml +++ b/molecule/distribution/converge.yml @@ -1,9 +1,15 @@ --- - name: Converge hosts: all + pre_tasks: + - name: Set package name if Alpine + ansible.builtin.set_fact: + nginx_package_name: "@nginx:1.24/common" + when: ansible_facts['os_family'] == "Alpine" tasks: - name: Install NGINX ansible.builtin.include_role: name: ansible-role-nginx vars: nginx_install_from: os_repository + nginx_distribution_name: "{{ nginx_package_name }}" diff --git a/tasks/opensource/install-distribution.yml b/tasks/opensource/install-distribution.yml index aabcd28f7..b5fe9a299 100644 --- a/tasks/opensource/install-distribution.yml +++ b/tasks/opensource/install-distribution.yml @@ -9,6 +9,6 @@ - name: "{{ nginx_setup | capitalize }} NGINX from the distribution's package repository" ansible.builtin.package: - name: nginx{{ nginx_version | default('') }} + name: "{{ nginx_distribution_package | default('nginx' + (nginx_version | default(''))) }}" state: "{{ nginx_state }}" notify: (Handler) Run NGINX From f573cbc8ededc57ddfe8e2629d8d435280655653 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 24 Mar 2025 15:52:22 +0100 Subject: [PATCH 2/4] docs: Tweak CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc44b38d6..f2935ac88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ FEATURES: -- Add a parameter, `nginx_distribution_package`, to override the default NGINX package when installing NGINX from your distribution/OS repository. +- Add a parameter, `nginx_distribution_package`, to override the default NGINX package name when installing NGINX from your distribution/OS repository. BUG FIXES: From 31a13859a6d6276c4799e4d7a0985d8f93e72932 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 24 Mar 2025 16:16:58 +0100 Subject: [PATCH 3/4] fix: Use correct parameter in Molecule --- molecule/distribution/converge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule/distribution/converge.yml b/molecule/distribution/converge.yml index 1d43a6c9e..222dfca98 100644 --- a/molecule/distribution/converge.yml +++ b/molecule/distribution/converge.yml @@ -12,4 +12,4 @@ name: ansible-role-nginx vars: nginx_install_from: os_repository - nginx_distribution_name: "{{ nginx_package_name }}" + nginx_distribution_package: "{{ nginx_package_name }}" From 4d2626cb4023495ebe8fff8184bbb5e5aae4737b Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 24 Mar 2025 20:44:24 +0100 Subject: [PATCH 4/4] fix: Package name --- molecule/distribution/converge.yml | 6 +++--- molecule/distribution/verify.yml | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/molecule/distribution/converge.yml b/molecule/distribution/converge.yml index 222dfca98..ec952744f 100644 --- a/molecule/distribution/converge.yml +++ b/molecule/distribution/converge.yml @@ -2,10 +2,10 @@ - name: Converge hosts: all pre_tasks: - - name: Set package name if Alpine + - name: Set package name if Debian ansible.builtin.set_fact: - nginx_package_name: "@nginx:1.24/common" - when: ansible_facts['os_family'] == "Alpine" + nginx_package_name: nginx-core + when: ansible_facts['os_family'] == "Debian" tasks: - name: Install NGINX ansible.builtin.include_role: diff --git a/molecule/distribution/verify.yml b/molecule/distribution/verify.yml index 3e6cc4bc4..a0f19faee 100644 --- a/molecule/distribution/verify.yml +++ b/molecule/distribution/verify.yml @@ -8,6 +8,16 @@ state: present check_mode: true register: install + when: ansible_facts['os_family'] != 'Debian' + failed_when: (install is changed) or (install is failed) + + - name: Check if NGINX is installed + ansible.builtin.package: + name: nginx-core + state: present + check_mode: true + register: install + when: ansible_facts['os_family'] == 'Debian' failed_when: (install is changed) or (install is failed) - name: Check if NGINX service is running