Ansible contd…
- In Ansible we can execute the activity by using
- adhoc command:
- Can execute any ansible module
- Good for rare activities
- history cannot be maintained
- Playbook: declaring the whole deployment as a yaml file
- Good for automating activities used multiple times (frequently)
- Playbook can be version controlled, so we will have history of all of the changes done.
Lets create a file using Ansible
- Refer Here for the file module
- Adhoc command:
ansible -m <module-name> -a <parameters/arguments> -i <inventory> all
- module-name => ansible.builtin.file
- arguments:
- state argument: touch
- path: /tmp/1.txt
ansible -m ansible.builtin.file -a 'path=/tmp/1.txt state=touch' all
- Playbook:
---
- name: learning playbooks
hosts: all
become: no
tasks:
- name: create a empty file
ansible.builtin.file:
path: /tmp/1.txt
state: touch

Lets Use Ansible to deploy a Java application on Tomcat server
sudo apt update
sudo apt install openjdk-8-jdk -y
sudo apt install tomcat9 -y
wget https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war
sudo cp gameoflife.war /var/lib/tomcat9/webapps/
sudo systemctl restart tomcat9.service
- Today lets install java using Ansible Playbook
- For updating and installing java Refer Here
- Created the ansible playbook Refer Here for the playbook

Like this:
Like Loading...