Skip to content

Instantly share code, notes, and snippets.

@algotrader-dotcom
Last active October 7, 2015 07:25
Show Gist options
  • Save algotrader-dotcom/0f40ffdf3a461c2f368e to your computer and use it in GitHub Desktop.
Save algotrader-dotcom/0f40ffdf3a461c2f368e to your computer and use it in GitHub Desktop.
Ansible HowTos
# /etc/ansible/hosts
[project1]
192.168.175.30 ansible_ssh_user=sysadmin ## nginx - load balancer
192.168.175.51 ansible_ssh_user=sysadmin ## web1
192.168.175.52 ansible_ssh_user=sysadmin ## web2
192.168.175.50 ansible_ssh_user=sysadmin ## MySQL
192.168.175.56 ansible_ssh_user=sysadmin ## MongoDB
[localhost]
127.0.0.1 ansible_ssh_user=ansible
[local-office]
172.16.120.34 ansible_ssh_user=ansible
# Summary Installation
## Install ansible on control host (master) named master-node
- Create user ansible on all masters (slave nodes will be managed) and make sure from master-node can SSH to all slave-node
- On master-node: Generate key pair with ssh-key-gen then copy public key (ssh-key-copy) to all slave-nodes
- Update /etc/ansible/hosts as aboved.
## Check if it works
On master-node: $ansible all -m ping, you can replace all with group nodes such as: project1, localhost, local-office
# Some useful adhoc commands
1. Ping all slave-node
$ansible all -m ping
2. Execute "df -h" on all slave nodes
$ansible all -a "sudo df -h"
$ansible all -m shell -a "uptime"
or
$ansible all -m shell -a "sudo df -h"
3. Gather all facts
$ansible all -m setup
4. List all hosts in inventory file
$ansible -i hosts all --list-hosts
or
$ansible -i hosts -m setup HOSTNAME
# Ansible Windows Integration
# References
Adhoc Intro: http://docs.ansible.com/ansible/intro_adhoc.html#gathering-facts
Ansible bootstrap playbook: thornelabs.net/2014/03/08/install-ansible-create-your-inventory-file-and-run-an-ansible-playbook-and-some-ansible-commands.html
Ansible Amazon: http://www.slideshare.net/bfschott/using-ansible-dynamic-inventory-with-amazon-ec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment