Beruflich Dokumente
Kultur Dokumente
Ansible
Getting Started
Overview
Introduction to Ansible
Advantages of using Ansible
How does Ansible work?
Installation Guide
Introduction to Ansible
• Ansible is a radically simple IT automation platform that makes your applications and systems
easier to deploy.
• Very simple to set up and use. No special coding skills are necessary to use Ansible’s
playbooks (more on playbooks later).
• Flexible. You can orchestrate the entire application environment no matter where it’s
deployed. You can also customize it based on your needs.
• Agentless. You don’t need to install any other software or firewall ports on the client systems
you want to automate. You also don’t have to set up a separate management structure.
• Efficient. Because you don’t need to install any extra software, there’s more room for
application resources on your server.
How does Ansible work?
Installtion Step:
• Install Epel repository on your system:
sudo yum -y install epel-release
• Install Ansible:
sudo yum -y install ansible
Review
Introduction to Ansible
Advantages of using Ansible
How does Ansible work?
Installation Guide
Working with command line tools
Overview
ansible-console* Running Ansible in console mode and execute command in remote hosts
ansible-vault* Encrypt any structured data file used by Ansible: group_vars, host_vars,
Inventory variables...
Ansible and Ansible-playbook command
ansible ansible-playbook
• Execute Automate task on remote hosts via • Execute Automate tasks on remote hosts via
command (single tasks). pre-defined playbook (multiple tasks)
• Known as Ad-hoc Command • Example:
• Example:
Review
List of Ansible Command Line/Utilities
Ansible and Ansible-playbook command
Introduction in Ad-hoc Commands
Overview
Effective for one-time commands, operational Effective for deployments, routine tasks, system
activities, information gathering and research deployment
YAML
INI
Static vs Dynamic
Static Dynamic
• Specifying an executable file as the • The program script must return JSON in the
inventory is considered a dynamic inventory format Ansible expecting
• JSON ouput is expected to be return to • Do not forget to make the file executable:
STDOUT from the executable o chmod +x dynamic.py
• The implementation (python, java, C, bash, • Using dynamic inventories, you can pull
etc) does not matter as long as the program inventory information from like of:
can run on the control host and behaves as o A cloud provider
Ansible expects o LDAP
• The program/script must respond to two o Cobbler
possible parameters: o Other CMDB Software
o --list
o --host [hostname]
Some Popular Options
• Cobbler
• AWS EC2
• VMware
• Openstack
• Plenty of documentation available
Review
Use both static and dynamic inventories to define group of hosts:
What is the inventory
File formats
Static vs Dynamic
Utilize an existing dynamic inventory script:
On dynamic inventories
Some Popular options
Working With Modules
Overview
Introduction to modules
Return values
Common modules
Introduction to Modules
• Ansible ships with a number of modules (called the 'module library') that can be
executed directly on remote hosts or through Playbooks.
• User can write their own modules. These modules can control system resources, like
service, packages, files or handle executing system commands.
• Modules index:
https://docs.ansible.com/ansible/latest/modules/modules_by_categ
ory.html
Return values
• Ansible modules normally return a data structure
that can be registered into a variable, or seen
directly when output by the ansible program.
File Git
Work with files Interac with git repositories
• When ---
See more
https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html
Selective Run Specified Tasks inn Playbooks Using Tags
If you have a large playbook, it may become useful to be able to run only a specific part of it
rather than running everything in the playbook
or
See more
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html
Review
Know how to work with commonly used Ansible modules
Create playbooks to configure system to specified state
Use variables to retrive the results of running commands
Use conditional to control play execution
Configure error handling
Selective runs specified tasks in playbooks using tags
Working With Patterns
Overview
- In Playbook
- Using all or * to execute all Hosts in - Using all or * to execute all Hosts in inventory
inventory
Common Patterns
File-level encryption Ansible Vault can encrypt any structured data file used by Ansible.
Variable-level encryption Supports encrypting single values inside a YAML file, using
the !vault tag to let YAML and Ansible know it uses special processing
How to use?
• Encrypt inventory file
How to use?
• Run Ansible with Encrypted inventory file => ERROR
How to use?
• Run Ansible with Encrypted inventory file with --ask-vault-pass
Number of
20 11
Modules
Ansbile build-in modules Juniper JunOS Ansible modules
junos_banner juniper_junos_command
junos_command juniper_junos_pmtud
junos_config juniper_junos_jsnapy
junos_facts juniper_junos_software
junos_interface juniper_junos_rpc
junos_l2_interface juniper_junos_facts
junos_l3_interface juniper_junos_system
junos_linkagg juniper_junos_config
junos_lldp juniper_junos_ping
junos_lldp_interface juniper_junos_table
junos_logging juniper_junos_srx_cluster
List Modules junos_netconf
junos_package
junos_rpc
junos_scp
junos_static_route
junos_system
junos_user
junos_vlan
junos_vrf
THANK YOU