Installing Ansible on Ubuntu 18.04 and running simple commands

INSTALL:
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible

CONFIGURE:
*Edit '/etc/ansible/hosts'
*Define 'hosts' - or Ansible clients. Create a group called 'ahosts':

[ahosts]
host1 ansible_ssh_host=192.168.1.28

*Tell Ansible to use python interpreter in path /usr/bin/python3 (shipped with Ubuntu 18.04)

[servers:vars]
ansible_python_interpreter=/usr/bin/python3

*Tell Ansible to use username 'ak' when connecting to hosts (if not using SSH keys):
*Make dir '/etc/ansible/group_vars'
*Edit '/etc/ansible/group_vars/servers'

---
ansible_ssh_user: ak

RUN COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m ping ahosts

RUN COMMAND ON HOSTS 'host1' AND 'host2' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m ping host1:host2

RUN SHELL COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m shell -a 'free -m' ahosts

RUN SHELL COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m shell -a 'touch file.txt' ahosts

Kommentarer

Populære opslag fra denne blog

Microsoft Office 2016 and the AUTO_ACTIVATE property

Disable logon and logoff events (event id 4624, 4625, 4634 (and all the other ones...))

Enable OpenELEC SSH login with keys, and without password, disable local SSH password