What's new in Ansible 2.0
-
Upload
allan-denot-medeiros -
Category
Technology
-
view
1.750 -
download
0
Transcript of What's new in Ansible 2.0
What's new in Ansible 2.0
Allan Denot
∙ 2 year experience with Ansible
∙ 3 years experience with AWS
∙ Senior DevOps Engineer at Odecee
∙ Co-founder of spikenode.com
@denot allandenot.com
Allan Denot @denot allandenot.com
∙ Brazilian
∙ 5 years in Australia
New in Ansible 2.0
What’s New
Refactoring
● Improved variable management● Better use of OOP● Internal APIs
Many new modules
Language features
Release Date
September 8th:
Testing v2
git clone https://github.com/ansible/ansible.gitcd ansible. v2/hacking/env-setup
Strategies
- hosts: all gather_facts: no strategy: free tasks: - pause: seconds={{ 10 |random}} - debug: msg="msg_1" - pause: seconds={{ 10 |random}} - debug: msg="msg_2" - pause: seconds={{ 10 |random}} - debug: msg="msg_3"
Execution StrategiesExample playbook:
Execution Strategiesstrategy: linear (default)
TASK [debug msg=msg_1] ********************************************************** ok: [host3] => { "msg": "msg_1", "changed": false} ok: [host4] => { "msg": "msg_1", "changed": false} ok: [host2] => { "msg": "msg_1", "changed": false} ok: [host1] => { "msg": "msg_1", "changed": false}
TASK [debug msg=msg_2] ********************************************************** ok: [host4] => {"msg": "msg_2", "changed": false} ok: [host1] => {"msg": "msg_2", "changed": false} ok: [host2] => {"msg": "msg_2", "changed": false} ok: [host3] => {"msg": "msg_2", "changed": false}
TASK [debug msg=msg_3] ********************************************************** ok: [host1] => {"msg": "msg_3", "changed": false} ok: [host2] => {"msg": "msg_3", "changed": false} ok: [host3] => {"msg": "msg_3", "changed": false} ok: [host4] => {"msg": "msg_3", "changed": false}
PLAY [<no name specified>] ****************************************************** ok: [host3] => {"msg": "msg_1", "changed": false} ok: [host4] => {"msg": "msg_1", "changed": false} ok: [host2] => {"msg": "msg_1", "changed": false} ok: [host4] => {"msg": "msg_2", "changed": false} ok: [host2] => {"msg": "msg_2", "changed": false} ok: [host4] => {"msg": "msg_3", "changed": false} ok: [host1] => {"msg": "msg_1", "changed": false} ok: [host2] => {"msg": "msg_3", "changed": false} ok: [host3] => {"msg": "msg_2", "changed": false} ok: [host3] => {"msg": "msg_3", "changed": false} ok: [host1] => {"msg": "msg_2", "changed": false} ok: [host1] => {"msg": "msg_3", "changed": false}
strategy: free
Blocks
tasks: - yum: name={{ item }} state=installed with_items: - httpd - memcached when: ansible_distribution == 'CentOS' become: true become_user: root
- template: src=templates/src.j2 dest=/etc/foo.conf when: ansible_distribution == 'CentOS' become: true become_user: root
- service: name=bar state=started enabled=True when: ansible_distribution == 'CentOS' become: true become_user: root
BlocksUntil 1.9:
REPETITIONREPETITIONREPETITIONREPETITIONREPETITION
tasks: - block: - yum: name={{ item }} state=installed with_items: - httpd - memcached
- template: src=templates/src.j2 dest=/etc/foo.conf
- service: name=bar state=started enabled=True
when: ansible_distribution == 'CentOS' become: true become_user: root
Blocks2.0:
tasks: - block: - name: Shell script to connect the app to a monitoring service. script: monitoring-connect.sh
rescue: - name: This will only run in case of an error in the block. debug: msg="There was an error in the block."
always: - name: This will always run, no matter what. debug: msg="This always executes."
Blocks for Error Handling2.0:
Modules
ModulesNotorious additions
package - generic OS package manager
- name: install the latest version of ntpdate package: name=ntpdate state=latest
# This uses a variable as this changes per distro.- name: remove the apache package package : name={{apache}} state=absent
expect - executes a command and responds to prompt
- expect: command: passwd username responses: (?i)password: "MySekretPa$$word
find - return a list of files based on criteria
# Recursively find /tmp files older than 4 weeks and equal or greater than 1 megabyte- find: paths="/tmp" age="4w" size="1m" recurse=yes
# Recursively find /var/tmp files with last access time greater than 3600 seconds- find: paths="/var/tmp" age="3600" age_stamp=atime recurse=yes
# find /var/log files equal or greater than 10 megabytes ending with .log or .log.gz- find: paths="/var/tmp" patterns="*.log","*.log.gz" size="10m"
ModulesEC2
iam
ec2_win_password
ec2_ami_findec2_ami_copy
ec2_vpc_subnetec2_vpc_igw
ecs_taskecs_clusterecs_taskdefinition
ec2_elb_facts
s3_loggings3_buckets3_lifecycle
dynamodb_table
route53_zoneroute53_health_check
IAM
EC2 windows
EC2 AMI
VPC
ECS
ELB
S3
DYNAMODB
ROUTE53
Compatibility
Playbooks
Playbooks should be 100% compatible,no changes required.
Using 2.0 modules TODAY
1 Go to https://github.com/ansible/ansible-modules-core/
Using 2.0 modules TODAY
2 Browse to the module
3
Using 2.0 modules TODAY
4 Save the module file (or copy/paste)
Using 2.0 modules TODAY
5 Save under: library/cloud/amazon/iam2.py
6 Use it normally: tasks:- name: Create two new IAM users with API keys iam2: iam_type: user name: "{{ item }}" state: present password: "{{ temp_pass }}" access_key_state: create with_items: - jcleese - mpython
And finally...
There’s a good chance that Tower will be open sourced…
Questions?
Links
github.com/adenot
allandenot.com
spikenode.com