how to install on command and control server
First step install Ansible on your command and control server (laptop or workstation, lol). This section shows the process I used on Fedora.
install system dependancy
sudo yum -y install sshpass
clone the git repo and create python virtualenv
git clone git://github.com/ansible/ansible.git cd ansible virtualenv .env
source the environment scripts
source ./hacking/env-setup source ./.env/bin/activate
install ansible and dependencies into python virtualenv
python setup.py develop
create an ansible hosts file in /etc/ansible/hosts
sudo mkdir /etc/ansible sudo vim /etc/ansible/hosts
put your targets into /etc/ansible/hosts for example
ansible all -m ping --ask-pass
Ansible assumes SSH keys, but may also use passwords, which is invoked with the --ask-pass flag. Invoke the --ask-sudo-pass flag if you need to supply a sudo password.
ansible configuration files
By default ansible looks to /etc/ansible for its configurations. In this section we document some of the configuration files ansible works with.
- This file lists all ansible managed hosts and group mappings.
- This directory may hold one YAML file for each host. These files are used to pass host specific variables.
- This directory may hold one YAML file for each group. These files are used to pass group specific variables.
- This is a special group that matches all hosts and groups and holds variables for all hosts.
Behavioral inventory variables and parameters
Sometimes you always want to set specific Ansible/SSH/settings for a host, group of hosts, or all hosts.
For example, this all file causes Ansible to use the root SSH user:
--- ansible_ssh_user: root
Another example declares the parameters in the hosts file itself.
Here is a list of other behavioral inventory parameters which may be set in a host_vars or group_vars files: http://docs.ansible.com/intro_inventory.html#list-of-behavioral-inventory-parameters
how to prepare remote hosts
Ansible requires that remote hosts have an SSH service running, and that your public SSH key is setup. Ansible also requires that all remote hosts have Python 2.4.x and the python JSON library (python-simplejson). Python 2.6.x and above ship with JSON library in the stdlib, so nothing needs to be done if you are using a newer operating system.
run arbitary commands
ansible all --ask-pass -a "uptime"
get all facts
ansible all --ask-pass -m setup
change the amount of parallel forks, (default is 5)
ansible all --ask-pass -f 20 -a "uptime"
give path to a private key
ansible tutorial_nodes --private-key=id_rsa -m shell -a 'free -m'