Skip to content

Commit

Permalink
use flatten variables (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhan9san authored Oct 26, 2024
1 parent e4c2895 commit a336682
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
8 changes: 5 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -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."
15 changes: 12 additions & 3 deletions templates/override.conf.j2
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit a336682

Please sign in to comment.