Separate service start/stop from main playbook
This commit is contained in:
parent
556606234a
commit
ab4cc3e394
@ -50,18 +50,19 @@
|
||||
when:
|
||||
services_deploy_cloud_systemd_files.changed
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_cloud_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_cloud_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -72,6 +73,6 @@
|
||||
(services_deploy_cloud_config_files.changed or
|
||||
services_deploy_cloud_nextcloud_files.changed or
|
||||
services_deploy_cloud_systemd_files.changed) and
|
||||
not services_deploy_cloud_service_start.changed
|
||||
services_deploy_cloud_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
@ -37,18 +37,19 @@
|
||||
when:
|
||||
services_deploy_database_systemd_files.changed
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_database_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_database_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -58,6 +59,6 @@
|
||||
when:
|
||||
(services_deploy_database_password_file.changed or
|
||||
services_deploy_database_systemd_files.changed) and
|
||||
not services_deploy_database_service_start.changed
|
||||
services_deploy_database_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
@ -28,18 +28,19 @@
|
||||
when:
|
||||
services_deploy_git_systemd_files.changed
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_git_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_git_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -48,6 +49,6 @@
|
||||
scope: "user"
|
||||
when:
|
||||
services_deploy_git_systemd_files.changed and
|
||||
not services_deploy_git_service_start.changed
|
||||
services_deploy_git_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
@ -91,18 +91,19 @@
|
||||
\",from=\"{{ vpn_wireguard_address }}\",\
|
||||
no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-x11-forwarding"
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_lrproxy_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_lrproxy_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -115,6 +116,6 @@
|
||||
services_deploy_lrproxy_rsync_certificates_timer.changed or
|
||||
services_deploy_lrproxy_dhparam.changed or
|
||||
services_deploy_lrproxy_keypair.changed) and
|
||||
not services_deploy_lrproxy_service_start.changed
|
||||
services_deploy_lrproxy_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
@ -29,18 +29,19 @@
|
||||
when:
|
||||
services_deploy_notes_systemd_files.changed
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_notes_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_notes_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -49,6 +50,6 @@
|
||||
scope: "user"
|
||||
when:
|
||||
services_deploy_notes_systemd_files.changed and
|
||||
not services_deploy_notes_service_start.changed
|
||||
services_deploy_notes_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
@ -66,18 +66,19 @@
|
||||
{{ services_service_user_home }}/.config/{{ services_service_user_name }}/dhparam.pem"
|
||||
register: services_deploy_rproxy_dhparam
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_rproxy_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_rproxy_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -89,6 +90,6 @@
|
||||
services_deploy_rproxy_systemd_files.changed or
|
||||
services_deploy_rproxy_certbot_timer.changed or
|
||||
services_deploy_rproxy_dhparam.changed) and
|
||||
not services_deploy_rproxy_service_start.changed
|
||||
services_deploy_rproxy_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
@ -74,18 +74,19 @@
|
||||
when:
|
||||
services_deploy_www_webiste_git.changed
|
||||
|
||||
- name: "enable the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
- name: "get uid"
|
||||
ansible.builtin.getent:
|
||||
database: "passwd"
|
||||
key: "{{ services_service_user_name }}"
|
||||
|
||||
- name: "start the service"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
register: services_deploy_www_service_start
|
||||
- name: "get service status"
|
||||
ansible.builtin.command: >-
|
||||
systemctl --user show --property ActiveState --value
|
||||
{{ services_service_user_name }}.service
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
||||
changed_when: false
|
||||
register: services_deploy_www_service_active_state
|
||||
|
||||
- name: "restart the service"
|
||||
ansible.builtin.systemd:
|
||||
@ -94,6 +95,6 @@
|
||||
scope: "user"
|
||||
when:
|
||||
services_deploy_www_systemd_files.changed and
|
||||
not services_deploy_www_service_start.changed
|
||||
services_deploy_www_service_active_state.stdout == "active"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
||||
|
22
playbooks/roles/services/start/meta/argument_specs.yml
Normal file
22
playbooks/roles/services/start/meta/argument_specs.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
options:
|
||||
ansible_hostname:
|
||||
type: "str"
|
||||
required: true
|
||||
services_root_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_home_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_data_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_containers_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_service_name:
|
||||
type: "str"
|
||||
required: true
|
21
playbooks/roles/services/start/tasks/main.yml
Normal file
21
playbooks/roles/services/start/tasks/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: "set the user variables"
|
||||
ansible.builtin.import_role:
|
||||
name: "services/include"
|
||||
vars_from: "user"
|
||||
|
||||
- block:
|
||||
|
||||
- name: "enable pod-{{ services_service_name }}"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: true
|
||||
scope: "user"
|
||||
|
||||
- name: "start pod-{{ services_service_name }}"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "started"
|
||||
scope: "user"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
22
playbooks/roles/services/stop/meta/argument_specs.yml
Normal file
22
playbooks/roles/services/stop/meta/argument_specs.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
options:
|
||||
ansible_hostname:
|
||||
type: "str"
|
||||
required: true
|
||||
services_root_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_home_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_data_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_containers_directory:
|
||||
type: "str"
|
||||
required: true
|
||||
services_service_name:
|
||||
type: "str"
|
||||
required: true
|
21
playbooks/roles/services/stop/tasks/main.yml
Normal file
21
playbooks/roles/services/stop/tasks/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: "set the user variables"
|
||||
ansible.builtin.import_role:
|
||||
name: "services/include"
|
||||
vars_from: "user"
|
||||
|
||||
- block:
|
||||
|
||||
- name: "stop pod-{{ services_service_name }}"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
state: "stopped"
|
||||
scope: "user"
|
||||
|
||||
- name: "disable pod-{{ services_service_name }}"
|
||||
ansible.builtin.systemd:
|
||||
name: "pod-{{ services_service_name }}.service"
|
||||
enabled: false
|
||||
scope: "user"
|
||||
|
||||
become_user: "{{ services_service_user_name }}"
|
18
playbooks/services_start.yml
Normal file
18
playbooks/services_start.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
- name: "services : asgard"
|
||||
hosts: "asgard"
|
||||
|
||||
tasks:
|
||||
- name: "start"
|
||||
ansible.builtin.include_role:
|
||||
name: "services/start"
|
||||
apply:
|
||||
tags:
|
||||
- "services:{{ services_service_name }}"
|
||||
- "services:start"
|
||||
- "services:start:{{ services_service_name }}"
|
||||
- "services:{{ services_service_name }}:start"
|
||||
loop: "{{ services_host_services | dict2items | map(attribute='key') }}"
|
||||
loop_control:
|
||||
loop_var: "services_service_name"
|
||||
tags: "always"
|
18
playbooks/services_stop.yml
Normal file
18
playbooks/services_stop.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
- name: "services : asgard"
|
||||
hosts: "asgard"
|
||||
|
||||
tasks:
|
||||
- name: "stop"
|
||||
ansible.builtin.include_role:
|
||||
name: "services/stop"
|
||||
apply:
|
||||
tags:
|
||||
- "services:{{ services_service_name }}"
|
||||
- "services:stop"
|
||||
- "services:stop:{{ services_service_name }}"
|
||||
- "services:{{ services_service_name }}:stop"
|
||||
loop: "{{ services_host_services | dict2items | map(attribute='key') }}"
|
||||
loop_control:
|
||||
loop_var: "services_service_name"
|
||||
tags: "always"
|
Loading…
Reference in New Issue
Block a user