[libvirt] [libvirt-jenkins-ci PATCH 0/2] ansible: Improve service management

Rely on built-in functionality instead of reinventing the wheel. Andrea Bolognani (2): ansible: Use systemd module ansible: Use built-in init system detection ansible/tasks/jenkins.yml | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) -- 2.13.6

Using the module is preferable to calling systemctl(1) directly because it's better integrated into Ansible (eg. the task will be marked as "ok" instead of "changed" when the service has already been enabled) and allows us to perform service activation in a single step instead of two. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- ansible/tasks/jenkins.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ansible/tasks/jenkins.yml b/ansible/tasks/jenkins.yml index 087033d..563f220 100644 --- a/ansible/tasks/jenkins.yml +++ b/ansible/tasks/jenkins.yml @@ -48,12 +48,10 @@ when: - use_systemd -- name: Reload systemd status - command: systemctl daemon-reload - when: - - use_systemd - - name: Enable Jenkins agent - command: systemctl enable jenkins + systemd: + name: jenkins.service + enabled: yes + daemon_reload: yes when: - use_systemd -- 2.13.6

Ansible already exposes the type of init system in use through the ansible_service_mgr fact, so we can drop our own detection. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- ansible/tasks/jenkins.yml | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/ansible/tasks/jenkins.yml b/ansible/tasks/jenkins.yml index 563f220..9c8eda1 100644 --- a/ansible/tasks/jenkins.yml +++ b/ansible/tasks/jenkins.yml @@ -12,24 +12,6 @@ owner: jenkins group: jenkins -- name: Figure out how to start Jenkins agent - set_fact: - use_rc_local: true - use_systemd: false - when: - - ( os_name == 'FreeBSD' or - ( os_name == 'CentOS' and os_version == '6' ) or - ( os_name == 'Ubuntu' and os_version == '12' ) or - ( os_name == 'Ubuntu' and os_version == '14' ) ) - -- name: Figure out how to start Jenkins agent - set_fact: - use_rc_local: false - use_systemd: true - when: - - use_rc_local is not defined - - use_systemd is not defined - - name: Configure and enable Jenkins agent lineinfile: path: /etc/rc.local @@ -39,14 +21,14 @@ line: "nohup {{ sudo }} -u jenkins {{ bash }} -l -c '{{ java }} -jar /home/jenkins/slave.jar -jnlpUrl \"{{ jenkins_url }}\" -secret \"{{ jenkins_secret }}\"' >/var/log/jenkins.log 2>&1 &" insertbefore: '^exit .*$' when: - - use_rc_local + - ansible_service_mgr != 'systemd' - name: Configure Jenkins agent template: src: templates/jenkins.service.j2 dest: /etc/systemd/system/jenkins.service when: - - use_systemd + - ansible_service_mgr == 'systemd' - name: Enable Jenkins agent systemd: @@ -54,4 +36,4 @@ enabled: yes daemon_reload: yes when: - - use_systemd + - ansible_service_mgr == 'systemd' -- 2.13.6

On Wed, Oct 11, 2017 at 10:52:16AM +0200, Andrea Bolognani wrote:
Rely on built-in functionality instead of reinventing the wheel.
Andrea Bolognani (2): ansible: Use systemd module ansible: Use built-in init system detection
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
participants (2)
-
Andrea Bolognani
-
Pavel Hrdina