Advertisement

Ansible for beginners

Site Reliability Engineer
Jul. 10, 2017
Advertisement

More Related Content

Advertisement

Recently uploaded(20)

Ansible for beginners

  1. Ansible Quick Start Guide for Beginners
  2. Why Ansible? - Easy to Read (YAML) - Easy to Use (Modules Support) - Smooth Learning Curve - Lower Complexity, Higher Productivity - Agentless, NO AGENT, 100% Clean - Written in Python (Friendly to Linux Systems) - Supported by RedHat and Communities
  3. Comparison Language Agent Configuration Communication Difficulty Ansible Python No YAML OpenSSH ★☆ Chef Ruby, Erlang Yes Ruby SSL ★★★★ Puppet Ruby Yes Puppet DSL SSL ★★★☆ SaltStack Python Yes YAML ZeroMQ ★★☆
  4. The Basic Knowledge You Should Have Operation System - Debian, Ubuntu, CentOS, RedHat - Windows / Windows Server Scripting Languages - Bash or Native Shell for Linux-Based System - PowerShell or BatchScript for Windows System
  5. How does it work? Variables Inventories Playbooks Compile OpenSSH or WinRM Target ServersResources
  6. Inventory An INI-like configuration file for Host/Group definition [webapp] web1.example.com web2.example.com [mysql] mysql1.example.com mysql2.example.com [postgres] psql1.example.com [mysql] mysql1.example.com mysql2.example.com [postgres] psql1.example.com [database:children] mysql postgres [database:vars] foo=bar
  7. Variable Host/Group specific settings for the target defined in inventory <top-dir> host_vars/ - mysql1.example.com group_vars/ - mysql - postgres ansible_user=ubuntu ansible_port=2222 ansible_private_key_file=private_key # ansible_ssh_private_key_file=private_key
  8. Directory Layout <top dir> - inventory - group_vars/ - group1 - group2 - host_vars/ - host1 - host2 - playbook/ - tasks/ - main.yml - defaults/ - main.yml - handlers/ - main.yml - templates/ http://docs.ansible.com/ansible/playbooks_best_practices.html#directory-layout
  9. Preparation
  10. Setup Ansible on Control Node $ add-apt-repository ppa:ansible/ansible $ apt-get update $ apt-get install ansible OR $ pip install ansible
  11. Limitation for Control Node Control Node is recommend to be Linux, or Windows Subsystem for Linux (WSL) - http://docs.ansible.com/ansible/intro_windows.html#using-a-windows-control-machine
  12. Additional Setup for Controlling Windows To control Windows Slave with local User Account, no additional setup required To control Windows Slave with AD Account, the easiest way is to setup Kerberos $ apt-get install python-dev libkrb5-dev krb5-user $ pip install pywinrm[kerberos] # include “brackets” $ vim /etc/krb5.conf http://docs.ansible.com/ansible/intro_windows.html#kerberos
  13. Additional Setup for the Windows Slave Nodes The older Windows require extra setup to meet basic requirements 1. Windows 7, 8, Windows Server 2008 R2 a. .Net Framework >= 4.0 (reboot required) b. PowerShell >= 3.0 (reboot required) 2. Windows Remote Management (WinRM) 3. Apply Hotfix for Windows 7, 8, Windows Server 2008 R2, 2012 http://docs.ansible.com/ansible/intro_windows.html#windows-system-prep
  14. What About Linux Slave? Nope… there’s no prerequisites for Linux slave, except login user account… :-)
  15. Ansible - The First Step
  16. Configuration - ansible.cfg https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg [defaults] inventory = ./inventory log_path = ./ansible.log forks = 5 ask_sudo_pass = True ask_pass = True
  17. Configuration - inventory https://github.com/ansible/ansible/blob/devel/examples/hosts [linux] 192.168.0.1 [windows7] 192.168.0.100 [windows2008r2] 192.168.0.101 [windows:children] windows7 windows2008r2
  18. Ansible Ad-hoc Mode (Linux) $ ansible linux -m ping $ ansible linux -m shell -a 'echo hello-world' $ ansible linux -m stat -a 'path=/etc/passwd'
  19. Ansible Ad-hoc Mode (Windows) $ ansible windows -m win_ping $ ansible windows -m win_shell -a 'echo hello-world' $ ansible windows -m win_stat -a 'path=C:Users'
  20. Gathering Facts $ ansible all -m setup $ ansible linux -m setup $ ansible windows -m setup $ ansible all -m setup -a 'filter=ansible_*' $ ansible all -m setup -a 'gather_subset=network' http://docs.ansible.com/ansible/setup_module.html
  21. Playbook Define the behaviour of the “role” - playbook/ - tasks/ - main.yml - defaults/ - main.yml - handlers/ - main.yml - templates/
  22. Live Demo with the Real Cases
  23. Modules Supoprt All Modules - http://docs.ansible.com/ansible/modules_by_category.html Windows Specific Modules - http://docs.ansible.com/ansible/list_of_windows_modules.html
  24. Ansible Galaxy - Playbooks by Community https://galaxy.ansible.com/list#/roles
  25. Q & A
  26. Recommend to Read - https://www.ansible.com/quick-start-video - http://docs.ansible.com/ansible/playbooks_best_practices.html - https://www.ansible.com/blog/ansible-best-practices-essentials - http://docs.ansible.com/ansible/intro_windows.html
Advertisement