ansible basics
play

Ansible Basics Oleg Fiksel Security Consultant @ CSPI GmbH - PowerPoint PPT Presentation

A BOUT I NTRODUCTION A NSIBLE E ND Ansible Basics Oleg Fiksel Security Consultant @ CSPI GmbH oleg.fiksel@cspi.com | oleg@fiksel.info FrOSCon 2015 A BOUT I NTRODUCTION A NSIBLE E ND A GENDA A BOUT I NTRODUCTION Goals of this talk


  1. A BOUT I NTRODUCTION A NSIBLE E ND Ansible Basics Oleg Fiksel Security Consultant @ CSPI GmbH oleg.fiksel@cspi.com | oleg@fiksel.info FrOSCon 2015

  2. A BOUT I NTRODUCTION A NSIBLE E ND A GENDA A BOUT I NTRODUCTION Goals of this talk Configuration management A NSIBLE Key Points Ad hoc Approach Playbook Run Playbook Idempotence Facts Handlers Best practices Summary E ND Q & A Links

  3. A BOUT I NTRODUCTION A NSIBLE E ND A BOUT ME ◮ Security Consultant at CSPI (former MODCOMP) ◮ Main topics ◮ Automation ◮ Virtualisation ◮ Application Switching (load balancing) ◮ Perl Coding

  4. A BOUT I NTRODUCTION A NSIBLE E ND A BOUT MODCOMP ◮ Founded in 1976 as MODCOMP Inc. Since 1985 in Germany. ◮ Main scope: production of minicomputer for real-time environments. Example: NASA Space Shuttle Program. ◮ Development of real-time operating system Real/IX. ◮ 1990 - 1992 Cray and Bull equip their HPCs with Real/IX. ◮ 1995 New scope: Security Consulting. ◮ 1996 purchased by CSPI. ◮ Since 2015 re-branded as CSPI Germany.

  5. A BOUT I NTRODUCTION A NSIBLE E ND A BOUT CSPI ◮ 3 locations world wide: US, DE, UK. ◮ CSPI Germany (Köln) ~90 employees. ◮ 9 solution centers covering every aspect of IT-Security. ◮ An opportunity to work on big infrastructures with cutting edge technology.

  6. A BOUT I NTRODUCTION A NSIBLE E ND G OALS OF THIS TALK

  7. A BOUT I NTRODUCTION A NSIBLE E ND G OALS OF THIS TALK ◮ This is not a comparison of configuration management systems.

  8. A BOUT I NTRODUCTION A NSIBLE E ND G OALS OF THIS TALK ◮ This is not a comparison of configuration management systems. ◮ Basic theoretical understanding of configuration management.

  9. A BOUT I NTRODUCTION A NSIBLE E ND G OALS OF THIS TALK ◮ This is not a comparison of configuration management systems. ◮ Basic theoretical understanding of configuration management. ◮ Introduction to ansible.

  10. A BOUT I NTRODUCTION A NSIBLE E ND G OALS OF THIS TALK ◮ This is not a comparison of configuration management systems. ◮ Basic theoretical understanding of configuration management. ◮ Introduction to ansible. ◮ Practical examples using ansible.

  11. A BOUT I NTRODUCTION A NSIBLE E ND W HAT IS A GOAL OF CONFIGURATION MANAGEMENT ? Provide easy , repeatable and scalable provisioning and configuration management.

  12. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ?

  13. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ? ◮ easy

  14. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ? ◮ easy ◮ configuration is consolidated versioned

  15. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ? ◮ easy ◮ configuration is consolidated versioned ◮ repeatable

  16. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ? ◮ easy ◮ configuration is consolidated versioned ◮ repeatable ◮ provisioning produces every time the same result

  17. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ? ◮ easy ◮ configuration is consolidated versioned ◮ repeatable ◮ provisioning produces every time the same result ◮ scalable

  18. A BOUT I NTRODUCTION A NSIBLE E ND W HAT DOES THIS MEAN ? ◮ easy ◮ configuration is consolidated versioned ◮ repeatable ◮ provisioning produces every time the same result ◮ scalable ◮ provisioning can be done to any number of machines

  19. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS

  20. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS ◮ Fresh (started February 2012)

  21. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS ◮ Fresh (started February 2012) ◮ Simple

  22. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS ◮ Fresh (started February 2012) ◮ Simple ◮ YAML Syntax

  23. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS ◮ Fresh (started February 2012) ◮ Simple ◮ YAML Syntax ◮ straight forward running scenario

  24. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS ◮ Fresh (started February 2012) ◮ Simple ◮ YAML Syntax ◮ straight forward running scenario ◮ Agentless

  25. A BOUT I NTRODUCTION A NSIBLE E ND A NSIBLE K EY P OINTS ◮ Fresh (started February 2012) ◮ Simple ◮ YAML Syntax ◮ straight forward running scenario ◮ Agentless ◮ dependencies for node SSH + ( Python >= 2.5 | Python < 2.5 + python-simplejson)

  26. A BOUT I NTRODUCTION A NSIBLE E ND U SING ANSIBLE AS PSSH Ansible can be used as pssh. ansible − i 1 0 . 0 . 0 . 1 , 1 0 . 0 . 0 . 2 , a l l − m command − a ’/ bin/date ’

  27. A BOUT I NTRODUCTION A NSIBLE E ND U SING ANSIBLE AS PSSH Ansible can be used as pssh. ansible − i 1 0 . 0 . 0 . 1 , 1 0 . 0 . 0 . 2 , a l l − m command − a ’/ bin/date ’ Run /bin/date on machines 10.0.0.1 and 10.0.0.2.

  28. A BOUT I NTRODUCTION A NSIBLE E ND P LAYBOOK Playbooks are YAML. 1 --- 2 # http://www.withoutthesarcasm.com/ubuntu-motd-landscape/ 3 − hosts: a l l remote_user: root 4 tasks: 5 - name: remove landscape − c l i e n t 6 apt: name=landscape − c l i e n t s t a t e =absent purge=yes 7 - name: remove landscape − common 8 apt: name=landscape − common s t a t e =absent purge=yes 9

  29. A BOUT I NTRODUCTION A NSIBLE E ND R UN P LAYBOOK How to run a Playbook? ansible − playbook − i inventory_file playbook . yml ansible − playbook − i hostname1 , hostname2 , 1 9 2 . 1 6 8 . 0 . 1 0 , playbook . yml

  30. A BOUT I NTRODUCTION A NSIBLE E ND I DEMPOTENCE 1 Wikipedia Quote

  31. A BOUT I NTRODUCTION A NSIBLE E ND I DEMPOTENCE "Idempotence is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result." 1 1 Wikipedia Quote

  32. A BOUT I NTRODUCTION A NSIBLE E ND I DEMPOTENCE "Idempotence is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result." 1 Simple: Goal of ansible playbook is to define the desired state and not script you way to this state. 1 Wikipedia Quote

  33. A BOUT I NTRODUCTION A NSIBLE E ND E XAMPLE 1 1 ansible − i test − node , a l l − m s h e l l \ 2 − a ’ echo " 1 9 2 . 1 6 8 . 0 . 1 test − node " >> /etc/hosts ’

  34. A BOUT I NTRODUCTION A NSIBLE E ND E XAMPLE 2 1 ansible − i test − node , a l l − m l i n e i n f i l e \ 2 − a ’ dest=/etc/hosts l i n e=" 1 9 2 . 1 6 8 . 0 . 1 test − node " ’

  35. A BOUT I NTRODUCTION A NSIBLE E ND E XAMPLE 3 1 --- 2 − hosts: a l l tasks: 3 - name: clean up /etc/hosts 4 l i n e i n f i l e : dest=/etc/hosts regexp =192\.168\.0 s t a t e =absent 5 - name: add new /etc/hosts entry 6 l i n e i n f i l e : dest=/etc/hosts l i n e= "192.168.0.1 test-node" 7

  36. A BOUT I NTRODUCTION A NSIBLE E ND F ACTS Facts are fetched from a host and exported as variables, which can be used in playbooks.

  37. A BOUT I NTRODUCTION A NSIBLE E ND F ACTS Facts are fetched from a host and exported as variables, which can be used in playbooks. See all facts for a host: 1 ansible hostname − m setup 2 ansible − i hostname , a l l − m setup

  38. A BOUT I NTRODUCTION A NSIBLE E ND E XAMPLE 1 --- 2 − hosts: a l l tasks: 3 - name: "shutdown CentOS 6 and 7 systems" 4 command: /sbin/shutdown − t now 5 when: ans ib l e_di str ib utio n == "CentOS" and 6 ( ansible_distribution_major_version == "6" 7 or 8 ansible_distribution_major_version == "7" ) 9

  39. A BOUT I NTRODUCTION A NSIBLE E ND T URN OFF GATHERING FACTS IN A PLAYBOOK 1 --- 2 − hosts: a l l gather_facts: no 3 tasks: 4 - name: clean up /etc/hosts 5 l i n e i n f i l e : dest=/etc/hosts regexp =192\.168\.0 s t a t e =absent 6 - name: add new /etc/hosts entry 7 l i n e i n f i l e : dest=/etc/hosts l i n e= "192.168.0.1 test-node" 8

  40. A BOUT I NTRODUCTION A NSIBLE E ND H ANDLERS Handlers only run after all of the tasks are run, and they only run once, even if they are notified multiple times. They always run in the order that they appear in the playbook, not the notification order.

  41. A BOUT I NTRODUCTION A NSIBLE E ND E XAMPLE 1 --- 2 − hosts: webservers handlers: 3 - name: r e s t a r t apache 4 service: name=httpd s t a t e =restarted 5 tasks: 6 - name: ensure apache i s at the l a t e s t version 7 yum: name=httpd s t a t e = l a t e s t 8 - name: write the apache config f i l e 9 template: src=/srv/httpd . j 2 dest=/etc/httpd . conf 10 notify: 11 - r e s t a r t apache 12 - name: ensure apache i s running ( and enable i t at boot ) 13 service: name=httpd s t a t e =started enabled=yes 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend