proxy-stopping.yaml
Overview
This file defines an Ansible playbook designed to deploy a proxy service with the explicit intention to stop it. It targets a group of proxy hosts, optionally specified by an inventory pattern or variable, and applies configuration changes by invoking a predefined role called proxy. The playbook disables the proxy service by setting specific variables that indicate the proxy is not up and should be stopped.
Playbook Structure and Functionality
The playbook consists of a single play with the following components:
Name: "Deploy proxy service" — This descriptive name indicates the deployment action related to the proxy service.
Gather Facts: Disabled (
no) — Disables automatic gathering of system facts to reduce overhead during execution.Hosts: Determined dynamically by the variable
proxy_target, defaulting to the host groupproxyif the variable is not set. This allows flexibility in targeting specific proxy hosts or a range of hosts.Become: Enabled (
yes) — Ensures that the playbook runs with elevated privileges (typically usingsudo) to perform service management.Error Handling:
any_errors_fatal: true— Any failure during the execution of this play will cause the entire playbook run to abort immediately.Variables:
PROXY_UP: no— Explicitly indicates that the proxy service should not be running.PROXY_STOP: yes— Flags the proxy service to be stopped.
Roles: Applies the
proxyrole, which encapsulates tasks related to managing the proxy service. This role is expected to interpret the above variables to stop the service accordingly.
Variables in Context
proxy_target(optional): Used to dynamically define which hosts the playbook targets. If omitted, the playbook targets all hosts in theproxygroup.PROXY_UPandPROXY_STOP: Control flags that theproxyrole uses to determine whether to start or stop the proxy service. In this playbook,PROXY_UPis set tonoandPROXY_STOPtoyes, signaling the role to stop the proxy.
Interaction with Other Components
proxyRole: This playbook relies on theproxyrole to perform the actual operations on the proxy service. The role presumably contains tasks to start, stop, or configure the proxy based on the variables provided here.Host Inventory: The playbook interacts with a set of proxy hosts defined in the Ansible inventory under the group
proxyor dynamically via theproxy_targetvariable.Privilege Escalation: Uses Ansible's
becomefeature to execute commands with elevated permissions necessary for service management.
Usage Example
To stop proxy services on hosts proxy5 to proxy14, you could run:
ansible-playbook proxy-stopping.yaml -e "proxy_target=proxy[5:14]"
If you want to stop the proxy on all hosts grouped under proxy, simply run:
ansible-playbook proxy-stopping.yaml
Implementation Details
The playbook disables fact gathering to improve execution speed since the tasks do not require system facts.
The conditional host targeting via
proxy_targetallows flexible deployment scenarios.By setting
any_errors_fatal: true, this playbook ensures operational safety by aborting if any task fails during execution.The role-based design abstracts proxy management logic, promoting reuse and maintainability.
Mermaid Diagram
flowchart TD
A[proxy-stopping.yaml Playbook]
A --> B[Set Variables: PROXY_UP=no, PROXY_STOP=yes]
A --> C["Target Hosts: {{ proxy_target | default('proxy') }}"]
A --> D[Invoke Role: proxy]
D --> E[Role interprets variables]
E --> F[Stops Proxy Service on Hosts]
This flowchart illustrates the main workflow of the playbook: setting variables, selecting target hosts, invoking the proxy role, and stopping the proxy service accordingly.