Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Using Ansible Dynamic Inventory with Amazon EC2
1. Using Ansible Dynamic Inventory
with Amazon EC2
Brian Schott, CTO
Nimbis Services
brian.schott@nimbisservices.com
Using Ansible Dynamic Inventory for Amazon EC2 1
2. Something Borrowed…
Using Ansible Dynamic Inventory for Amazon EC2 2
http://www.slideshare.net/lorinh/
vagrant-ansible-and-openstack-on-your-laptop
http://www.ansible.com/ansible-book
3. Shell scripts are painful, Puppet & Chef
have steep learning curves
if [[ $EUID -eq 0 ]]; then
ROOTSLEEP=${ROOTSLEEP:-10}
echo "You are running this script as root."
echo "In $ROOTSLEEP seconds, we will create a user 'stack' and run as that
user"
sleep $ROOTSLEEP
# since this script runs as a normal user, we need to give that user
# ability to run sudo
if [[ "$os_PACKAGE" = "deb" ]]; then
dpkg -l sudo || apt_get update && install_package sudo
else
rpm -qa | grep sudo || install_package sudo
fi
if ! getent passwd stack >/dev/null; then
echo "Creating a user called stack"
useradd -U -s /bin/bash -d $DEST -m stack
fi
Source: devstack/stack.sh
Using Ansible Dynamic Inventory for Amazon EC2 3
4. Ansible big idea: very simple syntax,
SSH for communication
• Open Source
https://github.com/ansible/ansible
• Agentless
• Python
• YAML
• Jinja2
• SSH
Using Ansible Dynamic Inventory for Amazon EC2 4
http://ansible.com/ansible-resources
5. Example Ansible playbook: install ntp
---
- hosts: controller
tasks:
- name: ensure ntp packages is installed
action: apt pkg=ntp
- name: ensure ntp.conf file is present
action: copy src=files/ntp.conf dest=/etc/ntp.conf
owner=root group=root mode=0644
- name: ensure ntp service is restarted
action: service name=ntp state=restarted
Using Ansible Dynamic Inventory for Amazon EC2 5
6. Specify hosts in an inventory file
[controller]
192.168.206.130
[compute]
192.168.206.131
192.168.206.132
192.168.206.133
192.168.206.134
Using Ansible Dynamic Inventory for Amazon EC2 6
7. Run the playbook
$ ansible-playbook ntp.yaml
PLAY [controller] *********************
GATHERING FACTS *********************
ok: [192.168.206.130]
TASK: [ensure ntp packages is installed] *********************
ok: [192.168.206.130]
TASK: [ensure ntp.conf file is present] *********************
ok: [192.168.206.130]
TASK: [ensure ntp service is restarted] *********************
ok: [192.168.206.130]
PLAY RECAP *********************
192.168.206.130 : ok=4 changed=3
unreachable=0 failed=0
Using Ansible Dynamic Inventory for Amazon EC2 7
8. What did Ansible just do?
1. Made SSH connections to remote host(s)
2. Copied over Python modules and arguments
parsed from playbook file
3. Executed modules on remote machine
Using Ansible Dynamic Inventory for Amazon EC2 8
9. Can run a single action using
ansible command
$ ansible controller –m apt –a "pkg=ntp"
192.168.206.130 | success >> {
"changed": false,
"item": "",
"module": "apt"
}
Using Ansible Dynamic Inventory for Amazon EC2 9
10. Ansible scripts are idempotent: can
run multiple times safely
$ ansible-playbook ntp.yaml
PLAY [controller] *********************
GATHERING FACTS *********************
ok: [192.168.206.130]
TASK: [ensure ntp packages is installed]
*********************
ok: [192.168.206.130]
TASK: [ensure ntp.conf file is present] *********************
ok: [192.168.206.130]
TASK: [ensure ntp service is restarted] *********************
ok: [192.168.206.130]
PLAY RECAP *********************
192.168.206.130 : ok=4 changed=1
unreachable=0 failed=0
Using Ansible Dynamic Inventory for Amazon EC2 10
11. What does Ansible have to do with cloud?
Using Ansible Dynamic Inventory for Amazon EC2 11
http://docs.ansible.com/list_
of_cloud_modules.html
12. Ansible Dynamic Inventory Feature
Using Ansible Dynamic Inventory for Amazon EC2 12
http://docs.ansible.com/intro_dynamic_inventory.html
13. A Practical Example
Using Ansible Dynamic Inventory for Amazon EC2 13
https://github.com/electroniceagle/ansible-dc-ec2-tutorial
29. Thank You
• Brian Schott, CTO
Nimbis Services
brian.schott@nimbisservices.com
• https://github.com/electroniceagle/ansible-dc-ec2-tutorial
https://slideshare.net/bfschott
Using Ansible Dynamic Inventory for Amazon EC2 29
Notes de l'éditeur
Ansible scripts are called playbooks, that are organized into individual plays.
Ansible plays are collection of tasks. You also need to specify which hosts you’re running on.
This play has three tasks:
- Install the NTP package
- Copy over a local ntp.conf file
- Restart the ntp service
By default, ansible will look in /etc/ansible/hosts for the inventory file, you can override this to specify a different location.
The items that appear in green did not change state. With a real ansible run, yellow ones would change state.