From a336682bd1068d70936c43f0386df58263656c47 Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 26 Oct 2024 22:55:36 +0800 Subject: [PATCH] use flatten variables (#25) --- defaults/main.yml | 8 +++++--- molecule/default/verify.yml | 28 ++++++++++++++++++++++++++++ templates/override.conf.j2 | 15 ++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 molecule/default/verify.yml diff --git a/defaults/main.yml b/defaults/main.yml index 1d91147..6aa5457 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,9 +5,11 @@ jenkins_version: "2.452.4" jenkins_process_user: jenkins jenkins_process_group: "{{ jenkins_process_user }}" -jenkins_systemd_unit_envs: - java_opts: "-Djenkins.install.runSetupWizard=false" - jenkins_listen_address: 127.0.0.1 +# Jenkins systemd unit override.conf +jenkins_java_home: "" +jenkins_java_opts: "-Djenkins.install.runSetupWizard=false" +jenkins_listen_address: 127.0.0.1 +jenkins_secrets_file: "" jenkins_home: /var/lib/jenkins diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..fc0c302 --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,28 @@ +--- +- name: Verify Jenkins systemd unit environment variables + hosts: all + tasks: + - name: Read override.conf content + ansible.builtin.slurp: + src: /etc/systemd/system/jenkins.service.d/override.conf + register: override_conf_content + + - name: Decode override.conf content + ansible.builtin.set_fact: + override_conf_decoded: "{{ override_conf_content.content | b64decode }}" + + - name: Print decoded override.conf content + ansible.builtin.debug: + var: override_conf_decoded + + - name: Assert JAVA_OPTS is present + ansible.builtin.assert: + that: + - "'JAVA_OPTS=-Djenkins.install.runSetupWizard=false' in override_conf_decoded" + fail_msg: "JAVA_OPTS is not set correctly in override.conf." + + - name: Assert JENKINS_LISTEN_ADDRESS is present + ansible.builtin.assert: + that: + - "'JENKINS_LISTEN_ADDRESS=127.0.0.1' in override_conf_decoded" + fail_msg: "JENKINS_LISTEN_ADDRESS is not set correctly in override.conf." diff --git a/templates/override.conf.j2 b/templates/override.conf.j2 index 25cf313..c5d806b 100644 --- a/templates/override.conf.j2 +++ b/templates/override.conf.j2 @@ -1,4 +1,13 @@ [Service] -{% for key, value in jenkins_systemd_unit_envs.items() %} -Environment="{{ key | upper }}={{ value }}" -{% endfor %} +{% if jenkins_java_home is defined %} +Environment="JAVA_HOME={{ jenkins_java_home }}" +{% endif %} +{% if jenkins_java_opts is defined %} +Environment="JAVA_OPTS={{ jenkins_java_opts }}" +{% endif %} +{% if jenkins_listen_address is defined %} +Environment="JENKINS_LISTEN_ADDRESS={{ jenkins_listen_address }}" +{% endif %} +{% if jenkins_secrets_file is defined %} +Environment="SECRETS_FILE={{ jenkins_secrets_file }}" +{% endif %}