Ensure to remove service management if deploy state is "absent"

This commit is contained in:
Jeremy Gardais 2018-02-27 15:47:08 +01:00
parent 394b2ecdb5
commit 6cb121a5ea
5 changed files with 72 additions and 31 deletions

View File

@ -8,6 +8,7 @@
### Enhancements ### Enhancements
* Set a var to manage the state of the deployment by this role. * Set a var to manage the state of the deployment by this role.
* Ensure to remove service management if deploy state is "absent".
## v1.0 ## v1.0

View File

@ -24,8 +24,6 @@ A role to manage Flexlm daemon.
* **flexlm__lmutil_path**: The place to store `lmutil` bin [default: `/usr/local/bin/lmutil`]. * **flexlm__lmutil_path**: The place to store `lmutil` bin [default: `/usr/local/bin/lmutil`].
* **flexlm__user_name**: Username used to launch `lmgrd` [default: `flexlm`]. * **flexlm__user_name**: Username used to launch `lmgrd` [default: `flexlm`].
* **flexlm__licences**: Lists to manage vendor daemon and licence files [default: `[]`]. * **flexlm__licences**: Lists to manage vendor daemon and licence files [default: `[]`].
* **flexlm__service_manage**: If Licence Manager service should be managed with this role [default: `True`].
* **flexlm__service_enabled**: If Licence Manager service should be enable at startup [default: `True`].
* **flexlm__service_unit_content**: Template used to generate the previous file [default: `etc/systemd/system/flexlm.service.j2`]. * **flexlm__service_unit_content**: Template used to generate the previous file [default: `etc/systemd/system/flexlm.service.j2`].
## Example Playbook ## Example Playbook

View File

@ -26,17 +26,62 @@ flexlm__required_packages:
flexlm__deploy_state: 'present' flexlm__deploy_state: 'present'
# ]]] # ]]]
# ]]] # ]]]
# Server configuration [[[
# ------------------------
# bin # .. envvar:: flexlm__lmgrd_version [[[
#
# Specifies the version of ``lmgrd`` daemon.
# Use to differentiate lmgrd on multiple versions in case of incompatibility with a vendor daemon binary.
#
# A symlink will be create to ``lmgrd`` daemon to have a simpler name.
#
flexlm__lmgrd_version: '11.14.0.1' flexlm__lmgrd_version: '11.14.0.1'
flexlm__lmgrd_source: 'usr/local/bin/lmgrd'
# ]]]
# .. envvar:: flexlm__lmgrd_path [[[
#
# Path to store ``lmgrd`` daemon.
flexlm__lmgrd_path: '/usr/local/bin/lmgrd' flexlm__lmgrd_path: '/usr/local/bin/lmgrd'
flexlm__lmutil_source: 'usr/local/bin/lmutil'
# ]]]
# .. envvar:: flexlm__lmgrd_source [[[
#
# Path where ``lmgrd`` daemon source is stored.
flexlm__lmgrd_source: 'usr/local/bin/lmgrd'
# ]]]
# .. envvar:: flexlm__lmutil_path [[[
#
# Path to store ``lmutil`` daemon.
flexlm__lmutil_path: '/usr/local/bin/lmutil' flexlm__lmutil_path: '/usr/local/bin/lmutil'
# user # ]]]
# .. envvar:: flexlm__lmutil_source [[[
#
# Path where ``lmutil`` daemon source is stored.
flexlm__lmutil_source: 'usr/local/bin/lmutil'
# ]]]
# .. envvar:: flexlm__user_name [[[
#
# The user under which FlexLM daemons are running during normal operation.
flexlm__user_name: 'flexlm' flexlm__user_name: 'flexlm'
# ]]]
# .. envvar:: apache__service_name [[[
#
# The name of the Apache service.
flexlm__service_manage: True
# ]]]
# ]]]
# service
flexlm__service_enabled: True
flexlm__service_unit_content: 'etc/systemd/system/flexlm.service.j2'
# Lists to manage vendor daemon and licence files. # Lists to manage vendor daemon and licence files.
# flexlm_licences: # flexlm_licences:
# - name: matlab # - name: matlab
@ -49,9 +94,4 @@ flexlm__user_name: 'flexlm'
# ports: [ '27000', '33188' ] # not used right now # ports: [ '27000', '33188' ] # not used right now
flexlm__licences: [] flexlm__licences: []
# service
flexlm__service_manage: True
flexlm__service_enabled: True
flexlm__service_unit_content: 'etc/systemd/system/flexlm.service.j2'
# ]]] # ]]]

View File

@ -3,8 +3,7 @@
- name: restart flexlm services - name: restart flexlm services
service: service:
name: '{{ "flexlm-" + item.name }}' name: '{{ "flexlm-" + item.name }}'
state: restarted state: '{{ "restarted" if (flexlm__deploy_state == "present" and (item.service | d(True)) else "stopped" }}'
with_flattened: with_flattened:
- '{{ flexlm__licences }}' - '{{ flexlm__licences }}'
when: ( flexlm__service_manage and
( item.service | d(True) ))

View File

@ -19,7 +19,7 @@
createhome: False createhome: False
system: True system: True
# bin {{{ # lmgrd and lmutil binaries [[[1
- name: Add lmgrd bin - name: Add lmgrd bin
copy: copy:
src: '{{ flexlm__lmgrd_source + "." + flexlm__lmgrd_version }}' src: '{{ flexlm__lmgrd_source + "." + flexlm__lmgrd_version }}'
@ -44,9 +44,7 @@
group: '{{ flexlm__user_name }}' group: '{{ flexlm__user_name }}'
mode: 0755 mode: 0755
# }}} # VENDOR and licence [[[1
# VENDOR and licence {{{
- name: Add VENDOR DAEMON - name: Add VENDOR DAEMON
copy: copy:
src: '{{ item.bin_src }}' src: '{{ item.bin_src }}'
@ -71,9 +69,7 @@
when: (item.lic_src|d()) when: (item.lic_src|d())
notify: ['restart flexlm services'] notify: ['restart flexlm services']
# }}} # Manage services [[[1
# service {{{
- name: Add systemd unit - name: Add systemd unit
template: template:
@ -82,27 +78,34 @@
owner: 'root' owner: 'root'
group: 'root' group: 'root'
mode: '0644' mode: '0644'
register: flexlm__register_systemd_service register: flexlm__register_service
notify: ['restart flexlm services'] notify: ['restart flexlm services']
with_flattened: with_flattened:
- '{{ flexlm__licences }}' - '{{ flexlm__licences }}'
when: ( flexlm__service_manage and when: ( (flexlm__deploy_state == "present") and
( item.service | d(True) )) ( item.service | d(True) ))
- name: Purge systemd unit
file:
dest: '{{ "/etc/systemd/system/flexlm-" + item.name + ".service" }}'
state: absent
register: flexlm__register_service
notify: ['restart flexlm services']
with_flattened:
- '{{ flexlm__licences }}'
when: ( (flexlm__deploy_state == "absent") or
not ( item.service | d(True) | bool ))
- name: Reload systemd daemons - name: Reload systemd daemons
command: systemctl daemon-reload command: systemctl daemon-reload
notify: ['restart flexlm services'] notify: ['restart flexlm services']
when: (flexlm__service_manage and when: ( flexlm__register_service|changed )
flexlm__register_systemd_service|changed)
- name: SERVICE manage services - name: Manage services
service: service:
name: '{{ "flexlm-" + item.name }}' name: '{{ "flexlm-" + item.name }}'
state: started state: '{{ "started" if (flexlm__deploy_state == "present" and (item.service | d(True)) else "stopped" }}'
enabled: '{{ flexlm__service_enabled }}' enabled: '{{ item.service | d(True) | bool }}'
with_flattened: with_flattened:
- '{{ flexlm__licences }}' - '{{ flexlm__licences }}'
when: ( flexlm__service_manage and
( item.service | d(True) ))
# }}}