Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ansible

308 views

Published on

presentation from wordpress weekend

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Ansible

  1. 1. Michal Haták AUTOMATION FOR EVERYONE
  2. 2. Michal Haták • INIZIO Internet Media • Python / PHP / JS / AWS • @Twistacz • github.com/Twista
  3. 3. Automation • Minimize or reduce human intervention • Faster • Less error prone • Reproducible
  4. 4. Shell scripts ? • Hard to write • Hard to maintain • Error prone
  5. 5. Ansible ? • Configuration Management • Application Deployment • Multi-Tier Orchestration
  6. 6. Why Ansible ? • Agent-less (just SSH) • Easy • YAML - no coding required • Modules
  7. 7. Concept • Inventories • Modules • Plays and Playbooks • Tasks • Facts and Variables • Templates • Roles
  8. 8. # inventory.ini [webserver] wpweekend ansible_host=10.88.88.10 [localws] local ansible_connection=local Inventory - list of machines / groups
  9. 9. The super-power of Modules Cloud
 Clustering
 Commands
 Database
 Files
 Inventory
 Messaging
 Monitoring Network
 Notification
 Packaging
 Source Control
 System
 Utilities
 Web Infrastructure
 Windows
  10. 10. # main.yml - name: task name module_name: param_name_1 = param_value_1 - name: task 2 name module_name: param1 = val1 param2 = val2 Playbooks and Plays
  11. 11. # main.yml - name: download and extract WordPress unarchive: src=http://wordpress.org/wordpress-{{ wp_version }}.tar.gz dest={{ target_directory }} copy=no creates={{ target_directory }}/wordpress Playbooks and Plays
  12. 12. # main.yml - name: create WordPress database mysql_db: name={{ wp_db_name }} state=present - name: create WordPress database user mysql_user: name={{ wp_db_user }} password={{ wp_db_password }} priv={{ wp_db_name }}.*:ALL host='localhost' state=present Playbooks and Plays
  13. 13. - name: change SSH port hosts: aws_launched tasks: - name: SSH port in configuration is 12345 replace: dest=/etc/ssh/sshd_config regexp='^Port 22$' replace='Port 12345' backup=yes become: True tags: ssh - name: SSH service restarted service: name=ssh state=restarted become: True tags: ssh Playbooks and Plays
  14. 14. - name: bower package npm: state=present global=yes name=bower - name: bower packages bower: path={{ install_dir }}/app/static sudo: no tags: deploy Playbooks and Plays
  15. 15. - name: git installed apt: state=present name=git - name: clone destination exists file: state=directory path={{ install_directory }} - name: repository is at given tag/commit or latest master git: repo={{ repository_url }}.git dest={{ install_directory }} version={{ version }} tags: deploy Playbooks and Plays
  16. 16. - name: system packages present apt: state=present name={{ item }} with_items: - python-dev - python-pip - python-lxml Playbooks and Plays
  17. 17. Facts and Variables • Work with machine data (hostname, ip, OS, devices) • Custom variables to re-use roles and playbooks
  18. 18. # group_vars/all target_directory: /tmp/wpweekend wp_version: 4.5.2 # These are the WordPress database settings wp_db_name: wordpress wp_db_user: wordpress wp_db_password: secret Facts and Variables
  19. 19. # templates/wp-config.php.j2 <?php define('DB_NAME', '{{ wp_db_name }}'); define('DB_USER', '{{ wp_db_user }}'); define('DB_PASSWORD', '{{ wp_db_password }}'); ... {{ wp_salt.stdout }} .... Templates
  20. 20. . └── my-role ├── README.md ├── defaults │   └── main.yml ├── files ├── handlers │   └── main.yml ├── meta │   └── main.yml ├── tasks │   └── main.yml ├── templates ├── tests │   ├── inventory │   └── test.yml └── vars └── main.yml Roles
  21. 21. Demo
  22. 22. Links • docs.ansible.com • https://medium.com/@Twistacz • http://www.root.cz/serialy/konfiguracni-a-orchestracni-nastroj- ansible/
  23. 23. Thanks! Questions ?

×