Simpler Ansible Playbook: Adding a deinstall.yml Task File for WebLogic Server Role
In this article, we will focus on creating a new Ansible playbook to handle the deinstallation of a WebLogic server. We will assume that you have already created a simple playbook to execute tasks, and now you want to add a deinstall.yml task file to it. We will cover the key concepts and provide detailed context on the topic, including subtitles and paragraphs, as well as code blocks enclosed within tags. The content inside the code blocks will be properly formatted according to the programming language, including indentation and tabulation where needed.
Prerequisites
Before we begin, it is essential to ensure that you have the following prerequisites in place:
- Ansible installed and configured on your system
- WebLogic server installed and running
- A simple Ansible playbook that can connect to and manage the WebLogic server
Creating the deinstall.yml Task File
To create the deinstall.yml task file, follow these steps:
- Create a new file named deinstall.yml in the same directory as your existing Ansible playbook.
- Add the following content to the file:
---
- name: Deinstall WebLogic Server
hosts: weblogic_servers
become: yes
tasks:
- name: Stop WebLogic Server
command: /u01/oracle/product/weblogic/user_projects/domains/mydomain/startWebLogic.sh -DstopServer=true
async: 0
poll: 0
ignore_errors: yes
- name: Wait for WebLogic Server to stop
wait_for_connection:
delay: 60
timeout: 3600
- name: Remove WebLogic Server installation directory
file:
path: /u01/oracle/product/weblogic
state: absent
The above playbook will stop the WebLogic server, wait for it to stop, and then remove the WebLogic server installation directory.
Adding the deinstall.yml Task File to Your Playbook
To add the deinstall.yml task file to your playbook, follow these steps:
- Open your existing Ansible playbook.
- Add the following content to the playbook:
---
- import\_tasks: tasks/install.yml
- import\_tasks: tasks/deinstall.yml
The above playbook will import the tasks from the install.yml and deinstall.yml task files. You can adjust the order of the import statements to control the execution order of the tasks.
Executing the deinstall.yml Task File
To execute the deinstall.yml task file, follow these steps:
- Save your Ansible playbook.
- Execute the playbook using the following command:
ansible-playbook playbook.yml -t deinstall
The above command will execute only the tasks tagged with "deinstall".
In this article, we have covered the following key concepts:
- Creating a new Ansible playbook to handle the deinstallation of a WebLogic server
- Adding a deinstall.yml task file to an existing Ansible playbook
- Executing the deinstall.yml task file using the Ansible command line
References