Ansible

Key-terms

  1. role
  2. Jinja2/ template (.j2) = offering dynamic vars and facts
  3. Facts = vars that related to remote systems, OS, IP, attached file systems
  4. Magic vars = vars about ansible itself (?)
  5. Public Cloud (e.g. Amazon, Azure)
  6. Private Cloud (e.g. VMAre)

Udemy - Intro to Ansible

Objectives

  1. Intro to Ansible
  2. Ansible Configs
  3. Ansible Inventory
  4. Ansible Facts and vars
  5. Ansible playbook (all .yaml)
  6. Ansible Modules and plugins
  7. Ansible handlers
  8. Ansible Templates
  9. Reusing ansible content

Section 1: Intro to Ansible

  1. Ansible takes away repetitive tasks & long boring commands. As it helps with the following
    • Resource Provision (migration, applying patches, sizing, creating new hosts, compliance, security audits)
    • Config management
    • CD
    • App Deployment
    • Security Compliance

      Note: Ansible works on DB servers, other boxes, cloud web servers, localhost!

  2. Ansible = IT automation tool made simple, powerful and agentless (unlike chef, salt & puppet)
  3. Ansible real use case examples:
    • e.g. 1: Shutting down web server then shut down DB, turn on DB first, turn on Web server last
    • e.g. 2: Setting up infra on both public + private clouds (on-prem), hundreds of VMs then set up connections between the apps between public and private (+config, setting up firewall rules, …)
  4. Ansible built in modules support use cases such as e.g. 1 and e.g. 2
  5. Ansible can pull live statuses…such as the following:
    • Data from CMDB to get list of target VMs
    • Trigger config when SNOW tickets gets approved
  6. Go check ansible documentation

  7. Ansible labs will be on KodeKloud

Section 2: Ansible config files

  1. Logics in ansible
    • Ansible will always look for a config file, default look up location is /etc/ansible/ansible.cfg
    • Ansible config file governs and controls the default behavior using a set of params
    • For introduction, here are 7 common Ansible section types
      • [defaults] = locations to modules (libs), roles, logs, plugins…
        • Example
             [defaults]
                              
             inventory           = /etc/ansible/hosts
             log_path            = /var/log/ansible.log
          
             library             = /usr/share/my_modules/
             roles_path          = /etc/ansible/roles
             action_plugins      = /usr/share/ansible/plugins/action
                              
             gathering           = implicit # Whether Ansible should be gathering facts as default. Implicit is yes, explicit is no
          
             timeout             = 10 # How long before giving up an ssh connection
             forks               = 5  # How many hosts should ansible target when executing playbooks
          
      • [inventory] = can enable certain inventory plugins, rest will discuss later
        • Example
             [inventory]
          
      • [privilage_esclation]
      • [paramiko_connection]
      • [ssh_connection]
      • [persistent_connection]
      • [colors]

Table of contents