Successfully reported this slideshow.

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

What's new in Ansible 2.0

  1. 1. What's new in Ansible 2.0
  2. 2. 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
  3. 3. Allan Denot @denot allandenot.com ∙ Brazilian ∙ 5 years in Australia
  4. 4. New in Ansible 2.0
  5. 5. What’s New Refactoring ● Improved variable management ● Better use of OOP ● Internal APIs Many new modules Language features
  6. 6. Release Date September 8th:
  7. 7. Testing v2 git clone https://github.com/ansible/ansible.git cd ansible . v2/hacking/env-setup
  8. 8. Strategies
  9. 9. - 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 Strategies Example playbook:
  10. 10. Execution Strategies strategy: 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
  11. 11. Blocks
  12. 12. 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 Blocks Until 1.9: REPETITIONREPETITIONREPETITIONREPETITIONREPETITION
  13. 13. 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 Blocks 2.0:
  14. 14. 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 Handling 2.0:
  15. 15. Modules
  16. 16. Modules Notorious 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"
  17. 17. Modules EC2 iam ec2_win_password ec2_ami_find ec2_ami_copy ec2_vpc_subnet ec2_vpc_igw ecs_task ecs_cluster ecs_taskdefinition ec2_elb_facts s3_logging s3_bucket s3_lifecycle dynamodb_table route53_zone route53_health_check IAM EC2 windows EC2 AMI VPC ECS ELB S3 DYNAMODB ROUTE53
  18. 18. Compatibility
  19. 19. Playbooks Playbooks should be 100% compatible, no changes required.
  20. 20. Using 2.0 modules TODAY 1 Go to https://github.com/ansible/ansible-modules-core/
  21. 21. Using 2.0 modules TODAY 2 Browse to the module 3
  22. 22. Using 2.0 modules TODAY 4 Save the module file (or copy/paste)
  23. 23. 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
  24. 24. And finally...
  25. 25. There’s a good chance that Tower will be open sourced…
  26. 26. Questions? Links github.com/adenot allandenot.com spikenode.com

×