Ansible Installation
- Ansible Installation steps on Ubuntu machine
sudo apt update
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
apt install ansible -y
sudo apt install ansible -y
ansible --version
If not able to get the ansible version follow the below steps
- Virtual Machine setup
Download and install kvm and install ubuntu 22.04 server edition and centos 7 minimal server with 1GB RAM.
https://ubuntu.com/download/server#downloads
http://isoredirect.centos.org/centos/7/isos/x86_64/
create a new virtual machine
Select Local install media and select the downloaded ISO Package.
set memory as "1024" CPU as "1"
set Disk image as "25" modify the name and Click Finish to complete the process.
Once done select the "Network&Hostname" Enable the Ethernet port.create the user account and set the root password.
Follow the below cmds to assign different IP when clone
echo -n > /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id
Ansible Config for target machine
- Enter the inventory and hosts entry on the ansible machine.
Get the ssh keygen (.ssh) and find the target machine IP using (hostname -I)
Copy the source machine ssh public key to the target machine
ssh-copy-id -i id_rsa.pub kannan@192.168.122.133
- If you want to change the hostname of the target machine go with the below cmd
sudo hostnamectl set-hostname ubuntu-node-1
exec bash
- Ping the target machine from ansible machine
ansible all -m ping
- Find the OS version of the target machine from ansible machine
ansible all -a "cat /etc/os-release"
- To provide root privileges for the users
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
sudo su-
usermod -aG sudo kannan
sudo su - kannan
- Let install Apache server(httpd) using adhoc cmds
ansible ubuntu -i hosts -m apt -a "name=apache2 state=present" --sudo
ansible all --list-hosts
ansible all -m package -a "name=httpd state=present"
ansible centos -m package -a "name=httpd state=present" -b
ansible centos -m ansible.builtin.service -a "name=httpd state=started" -b
ansible ubuntu -m file -a "path=/home/kannan/test mode=755 state=directory" -b
- Once Apache is installed on the Target machine bydefault its not active we need to enable,start and find the staus from ansible machine.
systemctl enable httpd
systemctl start httpd
systemctl status https
Now apache is running on the target machine.
We have done these all from ansible machine and get the output on target machine via ansible.
Top comments (0)