Skip to content

Instantly share code, notes, and snippets.

@CloudLinuxDeveloper
Last active August 12, 2021 23:04
Show Gist options
  • Save CloudLinuxDeveloper/58d01507b4082c5d2b8754221991f99f to your computer and use it in GitHub Desktop.
Save CloudLinuxDeveloper/58d01507b4082c5d2b8754221991f99f to your computer and use it in GitHub Desktop.
Install Ansible on Ubuntu
# !/bin/sh
https://www.youtube.com/watch?v=jp9Z0WlGt3s
# Installing Ansible
sudo apt update && sudo apt upgrade
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
# Setting Inventory File
sudo nano /etc/ansible/hosts
[servers]
server1 ansible_host=192.168.0.107
server2 ansible_host=192.168.0.108
server3 ansible_host=192.143.0.109
[servers:vars]
ansible_python_interpreter=/usr/bin/python3
#Single Host Vars Configuration
sudo mkdir /etc/ansible/host_vars
sudo nano /etc/ansible/host_vars/web-host1
ansible_ssh_host: 192.168.1.15
ansible_ssh_port: 22
ansible_ssh_user: root
# Check inventory file
ansible-inventory --list -y
ansiable --version
# Testing Connection
ansible all -m ping -u root
# Running Ad-Hoc Commands
ansible all -a "df -h" -u root
ansible all -m apt -a "name=vim state=latest" -u root
ansible servers -a "uptime" -u root
ansible server1:server2 -m ping -u root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment