What's new in Ansible 2.0

27
What's new in Ansible 2.0

Transcript of What's new in Ansible 2.0

Page 1: What's new in Ansible 2.0

What's new in Ansible 2.0

Page 2: 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

Page 3: What's new in Ansible 2.0

Allan Denot @denot allandenot.com

∙ Brazilian

∙ 5 years in Australia

Page 4: What's new in Ansible 2.0

New in Ansible 2.0

Page 5: What's new in Ansible 2.0

What’s New

Refactoring

● Improved variable management● Better use of OOP● Internal APIs

Many new modules

Language features

Page 6: What's new in Ansible 2.0

Release Date

September 8th:

Page 7: What's new in Ansible 2.0

Testing v2

git clone https://github.com/ansible/ansible.gitcd ansible. v2/hacking/env-setup

Page 8: What's new in Ansible 2.0

Strategies

Page 9: What's new in Ansible 2.0

- 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:

Page 10: What's new in Ansible 2.0

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

Page 11: What's new in Ansible 2.0

Blocks

Page 12: What's new in Ansible 2.0

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

Page 13: What's new in Ansible 2.0

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:

Page 14: What's new in Ansible 2.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:

Page 15: What's new in Ansible 2.0

Modules

Page 16: What's new in Ansible 2.0

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"

Page 17: What's new in Ansible 2.0

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

Page 18: What's new in Ansible 2.0

Compatibility

Page 19: What's new in Ansible 2.0

Playbooks

Playbooks should be 100% compatible,no changes required.

Page 20: What's new in Ansible 2.0

Using 2.0 modules TODAY

1 Go to https://github.com/ansible/ansible-modules-core/

Page 21: What's new in Ansible 2.0

Using 2.0 modules TODAY

2 Browse to the module

3

Page 22: What's new in Ansible 2.0

Using 2.0 modules TODAY

4 Save the module file (or copy/paste)

Page 23: What's new in Ansible 2.0

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

Page 24: What's new in Ansible 2.0

And finally...

Page 25: What's new in Ansible 2.0
Page 26: What's new in Ansible 2.0

There’s a good chance that Tower will be open sourced…

Page 27: What's new in Ansible 2.0

Questions?

Links

github.com/adenot

allandenot.com

spikenode.com