Ansible initial setup

ansible-install | ansible | ansible-ntp | ansible-rhel

requirements

make sure you’ve set up SSH without a password from the ansible system towards the target systems

install

see ansible-install

manual inventory

define hosts and groups to operate

cd /etc/ansible/

mv -i ansible.cfg ansible.cfg.dist
mv -i hosts hosts.dist

ansible-config init --disabled -t all > ansible.cfg.defaults.plugins
ansible-config init --disabled > ansible.cfg.defaults

get rid of the warning

vi ansible.cfg

[defaults]
interpreter_python=auto_silent

vi hosts

[servers]
FQDN:PORT   ansible_user=root
FQDN:PORT   ansible_user=root

[workstations]
LOCAL-HOSTNAME ansible_connection=local ansible_user=root

check

ansible all --list-hosts

make sure your ssh client knows the fingerprints

ssh FQDN -p PORT -l root
ssh FQDN -p PORT -l root

ready to go

check accessiblity of the managed systems

ansible all -m ping

send raw commands without using Python on the remote host e.g.

ansible all -m raw -a hostname

send shell commands using Python on the remote host e.g.

ansible all -m shell -a hostname

or print a remote variable e.g.

ansible all -m shell -a 'echo $TERM'

restart nginx on a specific host – beware json output is awefully long

ansible FQDN -m service -a "name=nginx state=restarted"

you can now proceed with playbooks

additional notes

inter-operatbility

if you are using ClusterIt aside Ansible, this script might be useful to maintain a shared list of hosts across both tools

echo -n converting clusterit.conf to ansible hosts file...
sed 's/GROUP:\(.*\)/\[\1\]/' /etc/clusterit.conf > /etc/ansible/hosts && echo done

resources

http://docs.ansible.com/ansible/intro_getting_started.html

http://docs.ansible.com/ansible/intro_configuration.html

http://docs.ansible.com/ansible/playbooks_conditionals.html

https://serversforhackers.com/an-ansible-tutorial

http://blog.programster.org/ansible-run-a-local-script-on-remote-server/

Ansible change ssh port in playbook https://stackoverflow.com/questions/34333058/ansible-change-ssh-port-in-playbook


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun