Skip to content

Commit

Permalink
Merge pull request #11 from p3ck/services_experience
Browse files Browse the repository at this point in the history
Configure Windows Services
  • Loading branch information
p3ck authored Dec 5, 2024
2 parents 2e8b186 + 6124548 commit a3ba954
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 0 deletions.
1 change: 1 addition & 0 deletions extensions/patterns/manage_service/exec_env/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
context/**
8 changes: 8 additions & 0 deletions extensions/patterns/manage_service/exec_env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Build EE manually, push to quay.io

```
ansible-builder build
# podman build -f context/Containerfile -t ansible-execution-env:latest context
podman tag ansible-execution-env:latest quay.io/p3ck/apd-ee-25-experience:latest
podman push quay.io/p3ck/apd-ee-25-experience:latest
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 3
images:
base_image:
name: quay.io/ansible-product-demos/apd-ee-25:latest
dependencies:
galaxy: requirements.yml
ansible_core:
package_pip: ansible-core
ansible_runner:
package_pip: ansible-runner
system:
- podman
6 changes: 6 additions & 0 deletions extensions/patterns/manage_service/exec_env/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
collections:
# - name: ansible.experience_demo
- name: https://github.com/redhat-cop/infra.windows_ops.git
type: git
version: main
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Manage Windows Services
hosts: all
gather_facts: false
tasks:
- name: Manage Windows Service
ansible.builtin.include_role:
name: infra.windows_ops.windows_manage_service
vars:
windows_manage_service_name: "{{ service_name }}" # Set by survey
windows_manage_service_state: "{{ service_state }}" # Set by survey
windows_manage_service_start_mode: "{{ service_start_mode }}" # Set by survey
...
47 changes: 47 additions & 0 deletions extensions/patterns/manage_service/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# Labels
#
controller_labels:
- name: infra.windows_ops
organization: "{{ organization | default('Default') }}"
- name: manage_service_pattern
organization: "{{ organization | default('Default') }}"
- name: run_manage_service
organization: "{{ organization | default('Default') }}"

# Execution Environments
#
controller_execution_environments:
- name: apd-ee-25-windows
description: Allow running Windows experience demo. Based on apd-ee-25.
image: quay.io/p3ck/apd-ee-25-experience:latest
pull: always

# Projects
#
controller_projects:
- name: Windows Operations / Project
organization: Default
scm_branch: main
scm_clean: 'no'
scm_delete_on_update: 'no'
scm_type: git
scm_update_on_launch: 'yes'
scm_url: https://github.com/redhat-cop/infra.windows_ops.git


# Job Templates
#
controller_templates:
- name: Windows Operations / Manage Service
ask_inventory_on_launch: true
labels:
- infra.windows_ops
- manage_service_pattern
- run_manage_service
playbook: "extensions/patterns/manage_service/playbooks/run_manage_service.yml' }}"
project: Windows Operations / Project
survey_enabled: true
survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/manage_service.yml') | from_yaml }}"
ask_credential_on_launch: true
execution_environment: apd-ee-25-windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: "Manage Service Configuration Survey"
description: "Survey to configure manage service options"
spec:
- question_name: "Service Name"
question_description: "Specify the Windows Service you would like to manage"
required: true
variable: "service_name"
type: "text"

- question_name: "Service State"
question_description: "Specify the state of the Service"
required: true
variable: "service_state"
type: "multiplechoice"
choices:
- "absent"
- "paused"
- "started"
- "stopped"
- "restarted"

- question_name: "Start mode"
question_description: "Set the startup mode for the Service"
required: false
variable: "service_start_mode"
type: "multplechoice"
choices:
- "auto"
- "delayed"
- "disabled"
- "manual"
default: "auto"
2 changes: 2 additions & 0 deletions roles/windows_manage_service/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
windows_manage_service_start_mode: "auto"
31 changes: 31 additions & 0 deletions roles/windows_manage_service/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
argument_specs:
main:
version_added: 1.0.0
short_description: A role to Manage Windows Services.
description:
- A role to Manage Windows Services.
options:
windows_manage_service_name:
type: str
description: The name of the service.
required: true
windows_manage_service_state:
type: str
choices:
- "absent"
- "paused"
- "started"
- "stopped"
- "restarted"
required: true
description: The state of the service.
windows_manage_service_start_mode:
type: str
choices:
- "auto"
- "delayed"
- "disabled"
- "manual"
default: "auto"
description: The start mode of the service.
18 changes: 18 additions & 0 deletions roles/windows_manage_service/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# tasks file for windows_manage_service

- name: Manage Windows Service
ansible.windows.win_service:
name: "{{ windows_manage_service_name }}"
state: "{{ windows_manage_service_state }}"
start_mode: "{{ windows_manage_service_start_mode }}"

- name: Check Win Service
ansible.windows.win_service_info:
name: "{{ windows_manage_service_name }}"
register: windows_manage_service_status

- name: Display Win Service
ansible.builtin.debug:
var: windows_manage_service_status
...

0 comments on commit a3ba954

Please sign in to comment.