Install Ansible
Download ez_setup.py.
sudo python ez_setup.py
sudo easy_install pip
sudo pip install ansible
sudo pip install jinja2
Define your host file
Create the file /etc/ansible/hosts.
Put the IP of each machine you want to ping.
Example:
[appservers]Change the IP to your EC2 instance's IP. The [appservers] is just a label for grouping. You may have servers grouped as web servers, app servers, db servers, etc.
255.255.255.255 ansible_ssh_private_key_file={your_key_path}.pem ansible_ssh_user=ec2-user
Run Ansible
ansible all -m ping
You will see a response similar to the following if it's successful.
255.255.255.255 | success >> {Let's execute a command on all the machines:
"changed": false,
"ping": "pong"
}
ansible all -a "/bin/echo hello"
You will see:
255.255.255.255 | success | rc=0 >>
hello
Saving the key in memory
If you don't specify the ansible_ssh_private_key_file and ansible_ssh_user attributes in the inventory file above. You can either 1.) specify the key and user in the ansible command or 2.) use ssh-agent.
1.) Explicitly specifying the user and key:
ansible all -m ping -u ec2-user --private-key={your_key}.pem2.) Using ssh-agent and ssh-add
ssh-agent bashThen you can ping the ec2 server like this:
ssh-add ~/.ssh/{your_key}.pem
ansible all -m ping -u ec2-user
No comments:
Post a Comment