Ansible
Adhoc commands
- Ansible allows us to automate individual commands using adhoc commands
ansible -m [module] -a "[module options]" [pattern]
ansible -i hosts -m file -a "path=/tmp/1.txt state=touch" all
- Lets try adding a user called as test
- homedirectory = “/opt/test”
- shell = “/bin/sh”
- username = “test”
ansible -i hosts -m user -a "name=test home=/opt/test shell=/bin/sh" all
Tomcat configuration.
sudo apt update
sudo apt install openjdk-17-jdk -y
sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.25/bin/apache-tomcat-10.1.25.tar.gz -P /tmp
sudo mkdir /opt/tomcat
sudo tar -xvf /tmp/apache-tomcat-10.1.25.tar.gz -C /opt/tomcat --strip-components=1
sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R g+r /opt/tomcat/conf
sudo chmod g+x /opt/tomcat/conf
- Ansible doesnot support –strip-components=1, so we need a workaround
- if you dont find the right module there is a way to run raw linux command. The side effect of this approach is no desired state and it executes every time.
- Change your manual steps accordingly
Lets take the approach 1: running raw linux commands
Better way