Complete ansible toolkit with generation and validation capabilities
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
A fintech company deploys their Java billing service to a group called app_servers. Deployments occasionally fail mid-way (e.g., the new JAR file is copied but the service fails to start), leaving servers in a broken state. The on-call team then spends 30 minutes manually rolling back.
The deployment process is:
/opt/billing/billing.jar to /opt/billing/billing.jar.bak/opt/billing/billing.jarIf any step from (3) onwards fails, the playbook should automatically restore the backup JAR and restart the service. Regardless of success or failure, the deployment status (success or failure with the error message) should be written to /var/log/ansible-deploy.log.
Produce a complete Ansible playbook file named deploy_billing.yml that implements the deployment with automatic rollback.
The following existing playbook stub is provided as a starting point. Extract it before beginning.
name: Deploy billing service hosts: app_servers become: yes
vars: billing_jar_src: "files/billing.jar" billing_jar_dest: "/opt/billing/billing.jar" billing_service_port: 8080
tasks:
name: stop billing service ansible.builtin.service: name: billing state: stopped ignore_errors: yes
name: backup current jar command: cp /opt/billing/billing.jar /opt/billing/billing.jar.bak
name: copy new jar copy: src: "{{ billing_jar_src }}" dest: "{{ billing_jar_dest }}" ignore_errors: yes
name: start service service: name: billing state: started ignore_errors: yes