Skip to content

Instantly share code, notes, and snippets.

@afahitech
Created April 8, 2020 11:41
Show Gist options
  • Select an option

  • Save afahitech/1e3467b224467b3a9d1d039f0545c0af to your computer and use it in GitHub Desktop.

Select an option

Save afahitech/1e3467b224467b3a9d1d039f0545c0af to your computer and use it in GitHub Desktop.
Install Ansible on Ubuntu 18.04 LTS
# !/bin/sh
# Installing Ansible
sudo apt update && sudo apt upgrade
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
# Setting Up the Inventory File
sudo nano /etc/ansible/hosts
[servers]
server1 ansible_host=192.168.0.106
server2 ansible_host=192.168.0.107
server3 ansible_host=192.143.0.105
[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
# youtube https://youtu.be/arvlxgz8YDc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment