Ansible How To
A simple video tutorial
OBS: ansible uses py, and py calls /bin/sh
, NOT bash
!
PRE-CONFIG #
suggested: use ssh-pub-key auth without passphrase.
INSTALL #
Optioanl: add ppa:ansible/ansible
installation:
sudo apt-get update && \
sudo apt-get install ansible
HOSTS #
vim /etc/ansible/hosts
master.ip.1
[slaves]
slave.domain1
slave.ip.addr.2
[slavesGroup2]
slave.domain2
slave.ip.addr.1
(see ref to give hosts’ names individually.)
SLAVE USERNAME #
sudo mkdir /etc/ansible/group_vars && \
sudo echo '---' > /etc/ansible/group_vars/all && \
sudo echo 'ansible_ssh_user: root' >> /etc/ansible/group_vars/all
(see DigitalOcean ref to config hosts individually.)
RUN #
try:
ansible -m ping all
-m
: module.
try:
ansible -m shell -a 'free -m' all
-a
: arguments.
try:
ansibleall () { ansible -m shell -a "$@" all; }
ansibleall 'wget -O /etc/apt/sources.list https://goo.gl/H78Ihs' && \
ansibleall 'rm /etc/localtime && ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime' && \
ansibleall 'apt-get update' && \
ansibleall 'apt-get install -y tmux vim ctags ntp mosh fail2ban sshguard locate'
ADVANCED #
echo 'ansibleall () { ansible -m shell -a "$@" all; }' >> ~/.bash_aliases
echo 'ansibleslaves () { ansible -m shell -a "$@" slaves; }' >> ~/.bash_aliases
echo 'ansiblemaster () { ansible -m shell -a "$@" master; }' >> ~/.bash_aliases
ref DigitalOcean