Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automating via Ansible

Automating via Ansible

Ansible is a configuration management and provisioning tool, similar to Chef, Puppet or Salt.
Here I'll show how easy it is to get started with Anible. We'll start basic and then add in more features as we improve upon our configurations.

Ompragash Viswanathan

November 06, 2017
Tweet

Other Decks in Technology

Transcript

  1. AGENDA WHAT IS ANSIBLE? ANSIBLE CORE COMPONENTS ANSIBLE GALAXY PROTECTING

    SENSITIVE DATA IN PLAYBOOK ADDITIONAL REFERENCES
  2. SIMPLE POWERFUL AGENTLESS Human readable automation No special coding skills

    needed Tasks executed in order Get productive quickly Application Deployment Continuous Delivery Beyond just Servers Orchestrate the App lifecycle Agentless architecture Uses OpenSSH and WinRM No exploits or updates More efficient and secure
  3. REQUIREMENTS CONTROL NODE MANAGED NODES 1 Ansible can be run

    from any machine with Python 2.6 or 2.7 1 Linux/Unix SSH 1.1 Python 2.4 or later 1.2 1.2.1 ​ If running less than Python 2.5 on the remotes nodes, package "python- simplejson" is required. Note: RHEL 5.x has Python 2.4 only. 2 Windows (Ansible 1.7+) - enable and configure PowerShell remoting 3.0+ (WinRM)
  4. ANSIBLE INVENTORY INVENTORY FILE HAS LIST OF ALL MANAGED HOST

    NAMES ONE LINE PER HOST FILES ARE ORGANIZED AS HOSTS AND GROUPS A SET OF HOSTS CAN BE UNDER A GROUP NAME A HOST CAN BE IN MORE THAN ONE GROUP DYNAMIC INVENTORY TO PULL FILES FROM DYNAMIC SOURCES AND CLOUDS
  5. ANSIBLE MODULES MODULES CONTROL SYSTEM RESOURCES - SERVICES, PACKAGES, FILES,

    SYSTEM COMMANDS, ETC. MODULE CAN BE EXECUTED DIRECTLY IN CLI OR THROUGH PLAYBOOKS LANGUAGE INDEPENDENT - RETURN JSON FORMAT DATA IDEMPOTENT - AVOIDS CHANGE TO SYSTEM UNLESS NEEDED
  6. RUNNING AD HOC COMMANDS TO EXECUTE AN AD HOC COMMAND,ADMIINISTRATORS

    NEED TO EXECUTE THE ANSIBLE COMMAND USING THE FOLLOWING SYNTAX: $ ansible host-pattern -m module [-a 'module argument'] [-i inventory]
  7. ANSIBLE COMMAND MODULES Ansible has four modules in to this

    category and provide us the options to choose from while running system commands or scripts: Raw - Do not require Python on target/managed host Command - Most recommended module for executing commands on target nodes Shell - Runs the command through the '/ bin/sh ' shell on the target host. It is less secure than a command module (can be affected by a shell environment) Script - copy and execute a script in one step on remote host
  8. CONFIGURATION FILES Certain settings in Ansible are adjustable via a

    configuration file. Ansible will select its configuration file from one of several possible locations on the control node, the file precedence is: Some configuration settings are: inventory - Change the location of the inventory file become - Enables or disables privilege escalation for operations on managed hosts. become_user - The user account to escalate privileges to on managed hosts. become_method - Defines the privilege escalation method on managed hosts Note: You can find many more options on /etc/ansible/ansible.cfg * ANSIBLE_CONFIG (an environment variable) * ansible.cfg (in the current directory) * .ansible.cfg (in the home directory) * /etc/ansible/ansible.cfg
  9. YAML YAML format - a simple, human-readable, and familiar way

    to blueprint the infrastructure. Playbooks are expressed in YAML format and have a minimum of syntax, which intentionally tries to not be a programming language or script, but rather a model of a configuration or a process.
  10. YAML EXAMPLE List in YAML file(a dash and a space).

    Dictionary in YAML file(key: value form).
  11. ANSIBLE PLAYBOOK PLAYBOOK CONTAIN PLAYS PLAYS CONTAIN TASKS TASKS CALL

    MODULE TASKS RUN SEQUENTIALLY TASKS TRIGGERS HANDLERS HANDLERS RUN ONCE AT THE END
  12. ANSIBLE VARIABLES Variables provide a convenient way to manage dynamic

    values for a given environment in yourAnsible project. Some examples of values that variables might contain include 1 Users to create 2 Packages to install 3 Services to restart 4 Files to remove 5 Archives to retrieve from the Internet
  13. ANSIBLE FACTS - Ansible facts are variables that are automatically

    discovered by Ansible from a managed host. - Facts are pulled by the setup module and contain useful information stored into variables that administrators can reuse. - Fact variables can be used as part of playbooks, in conditionals, loops, or any other dynamic statement that depends on a value for a managed host. - We can also create custom facts and push them to a managed node. Displaying facts from a hosts: ansible codestar.ansible.com -m setup
  14. ANSIBLE ROLES Roles provide Ansible with a way to load

    tasks, handlers, and variables from external files. Static files and templates can also be associated and referenced by a role. Roles can be written so they are general purpose and can be reused. 1 Roles group content, allowing easy sharing of code with others 2 Roles can be written that define the essential elements of a system type: web server, database server, git repository, or other purpose 3 Roles make larger projects more manageable 4 Roles can be developed in parallel by different administrators
  15. ANSIBLE GALAXY CLI TOOL $ ansible-galaxy search 'install git' --platforms

    el The ansible-galaxy command line tool can be used to search for, display information about, install, list, remove, or initialize roles. Identifying and installing roles
  16. ANSIBLE VAULT Protecting sensitive data in your playbooks. To create

    a new encrypted data file, run the following command: Similarly we can use edit, encrypt, decrypt and rekey, for more details on how to work with vault files, please check manual page: $ ansible-vault create secret.yml $ man ansible-vault