From 417f6fc58fc65307047769dac54b2704b572da38 Mon Sep 17 00:00:00 2001 From: Tristan Charbonneau Date: Fri, 4 Aug 2023 09:59:00 +0200 Subject: [PATCH 1/2] feat(service): manage service status and state Service can either be enabled or disabled, enabled by default Service can either be started, stopped, restarted, reloaded, started by default --- defaults/main.yml | 13 +++++++++++++ tasks/main.yml | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 40174da..e0b2e88 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -44,6 +44,19 @@ fusioninventory__agent_deploy_state: 'present' # The service name to manage. # fusioninventory__agent_service_name: 'fusioninventory-agent' + # ]]] +# .. envvar:: fusioninventory__agent_service_status [[[ +# +# The targeted service status. +# +fusioninventory__agent_service_status: 'started' + # ]]] + +# .. envvar:: fusioninventory__agent_service_enabled [[[ +# +# The targeted service status. +# +fusioninventory__agent_service_enabled: true # ]]] # .. envvar:: fusioninventory__agent_service_manage [[[ diff --git a/tasks/main.yml b/tasks/main.yml index 3ec261e..c4486f8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -56,3 +56,10 @@ mode: '0644' when: fusioninventory__agent_deploy_state == "present" notify: ['restart fusioninventory-agent service'] + +- name: Ensure the service is in the correct state + service: + name: "{{ fusioninventory__agent_service_name }}" + state: "{{ fusioninventory__agent_service_status }}" + enabled: "{{ fusioninventory__agent_service_enabled }}" + when: fusioninventory__agent_deploy_state == "present" From 4b2442b4e9b65bfa78b5b0728b43f49b7ce9f84c Mon Sep 17 00:00:00 2001 From: Tristan Charbonneau Date: Fri, 4 Aug 2023 10:04:56 +0200 Subject: [PATCH 2/2] chore: update README and CHANGELOG --- CHANGELOG.md | 1 + README.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1bf55..9710d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Enhancement * Upgrade package version from URL from 2.4 to 2.6 (thanks to @roumano - issue #15). +* Allow service to be managed, (thanks to @yodabzh - issue #17). ### Fix * Switch to Github URL to download deb file (thanks to @roumano - PR #16). diff --git a/README.md b/README.md index 3d29310..c18064d 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ A role to manage FusionInventory agent installation and configuration. * **fusioninventory__agent_service_name** : The service name to manage [default : `fusioninventory-agent`]. * **fusioninventory__agent_service_manage** : If the fusioninventory agent service should be managed [default : `true`]. * **fusioninventory__agent_conf_src** : Template used to provide agent configuration file [default : `../templates/etc/fusioninventory/agent.cfg.j2`]. +* **fusioninventory__agent_service_status**: Service state, can be started, stopped, restarted, reloaded [default : `started`]. +* **fusioninventory__agent_service_enabled**: Service status, can be enabled (`true`) or disabled (`false`) [default: `true`]. ### Config Specific Variables