SlideShare a Scribd company logo
Mike Dahlgren - miked@redhat.com
Tips and Tricks
Simple Tips and Tricks with Ansible
@KeithResar
Automating F5 Load Balancers
Automating your F5 Local traffic managers using Ansible.
Ready to run your first playbook?
Come and see what F5 Networks has been up to with ansible
playbooks. We will discuss and demo all the cool things you can
automate on your BIG-IP.
...presented on June 21st
@KeithResar
@KeithResar
@KeithResar
Mike Dahlgren - miked@redhat.com
Now for the Tips and Tricks
Running Commands in Parallel
PARALLELISM AND STRATEGIES COMMANDS
Number of forks can easily be defined with -f (default is 5)
$ ansible webservers -a "/sbin/reboot" -f 10
Strategies can be used to control play execution an can be changed
• Lineary strategy = in order execution (Default)
• Free strategy = finish as fast as you can
- hosts: all
strategy: free
tasks:
...
Removing Files & Directories
Removing a file from a server
Easy for one File:
$ ansible webservers -m file -a "dest=/path/to/file
state=absent"
Removing all the files and directory
- name: remove files and directories
file:
state: "{{ item }}"
path: "/srv/deleteme/"
owner: 1000 # set your owner, group, and mode
group: 1000
mode: '0777'
with_items:
- absent
- directory
Overloading the Ansible config
Set Defaults in a custom Ansible configuration file.
• No need to type -i myhosts from the CLI
• Remove the useless .retry files
• Can be used anywhere you run Ansible
Precedence model:
* ANSIBLE_CONFIG (an environment variable)
* ansible.cfg (in the current directory)
* .ansible.cfg (in the home directory)
* /etc/ansible/ansible.cfg
Forking background processes
from the command line
TIME LIMITING BACKGROUND OPERATIONS
Run script in background (30 Min timeout)
$ ansible webserver -B 3600 -P 0 -a "/bin/long_cmd --do-stuff"
Checking on the status of a previous job
$ ansible web1.example.com -m async_status -a "jid=488359678239.2844"
We can set how often to poll the status (60 seconds)
$ ansible webserver -B 1800 -P 60 -a "/bin/long_cmd --do-stuff"
Clean up your debugging tasks
Clean up your debugging tasks
- debug:
msg: "This always displays"
- debug:
msg: "This only displays with
ansible-playbook -vv+"
verbosity: 2
Use smoke tests
Don’t just start services -- use smoke tests
- name: check for proper response
uri:
url: http://localhost/myapp
return_content: yes
register: result
until: '"Hello World" in result.content'
retries: 10
delay: 1
Use Patterns
Use patterns quickly and effectively - Continued
Wildcards work
one*.com:dbservers
So can Regex
~(web|db).*.example.com
But would this work?
www[01:50].example.com, db-[a:f].example.com
Abusing Regex
Moving Drive letters in a Puppet Manifest
vars:
alphabet: "abcdefghijklmnopqrstuvwxyz"
tasks:
- block:
- name: change disk names
replace:
path: /etc/puppet/example/{{ hostname
}}.yaml
regexp: 'sd{{ alphabet[item | int + 1] }}'
replace: 'sd{{ alphabet[item | int] }}'
with_sequence: start=0 end=11
Leveraging Jinja2
Flow Control in Templates
{% for port in jmx_ports %}
<Connection>
ServiceURL "service:jmx:rmi:///jndi/rmi://{{
inventory_hostname }}.example.com:{{ port }}/jmxrmi"
Host "{{ inventory_hostname }}.example.com"
InstancePrefix "port_{{ port }}"
Collect "memory"
Collect "threads"
Collect "classes"
</Connection>
{% endfor %}
TASK [command]
*********************************
[WARNING]: Consider using yum module rather
than running yum
changed: [localhost]
@KeithResar
- hosts: all
tasks:
- command: yum -y install telnet
- yum: name=telnet state=present
- command: yum -y install telnet
args:
warn: False
@KeithResar
What is your favorite Trick?

More Related Content

PPTX
Rubyslava + PyVo #48
Jozef Képesi
 
PDF
Traceur - Javascript.next - Now! RheinmainJS April 14th
Carsten Sandtner
 
PDF
Ansible party in the [Google] clouds
Esther Lozano
 
PDF
What's new in Ansible 2.0
Allan Denot
 
PPTX
Gearman & PHP
Nemanja Krivokapic
 
PPTX
Web development-workflow
Qiu Juntao
 
PDF
Ansible
Michal Haták
 
PPTX
Jk rubyslava 25
Jozef Képesi
 
Rubyslava + PyVo #48
Jozef Képesi
 
Traceur - Javascript.next - Now! RheinmainJS April 14th
Carsten Sandtner
 
Ansible party in the [Google] clouds
Esther Lozano
 
What's new in Ansible 2.0
Allan Denot
 
Gearman & PHP
Nemanja Krivokapic
 
Web development-workflow
Qiu Juntao
 
Ansible
Michal Haták
 
Jk rubyslava 25
Jozef Képesi
 

What's hot (19)

PPTX
Scaling python webapps from 0 to 50 million users - A top-down approach
Jinal Jhaveri
 
PPTX
Scheduling torque-maui-tutorial
Santosh Kumar
 
PPTX
Ansible lightning talk at Scale 12
Justin Garrison
 
PDF
Rapid tests development
The Software House
 
PDF
Ansible 202
Sebastian Montini
 
PDF
Elasticsearch (R)Evolution — You Know, for Search… by Philipp Krenn at Big Da...
Big Data Spain
 
PPTX
Ac cuda c_1
Josh Wyatt
 
PDF
Sup intro
chase pettet
 
ODP
Use of django at jolt online v3
Jaime Buelta
 
PPTX
DJUGL - Django and AWS Lambda
Malcolm Box
 
ODP
Event Loop in Javascript
DiptiGandhi4
 
PPTX
Scaling with Python: SF Python Meetup, September 2017
Varun Varma
 
PDF
New Ways to Find Latency in Linux Using Tracing
ScyllaDB
 
PPTX
Sge
Chris Roeder
 
PDF
Deploying Rails Applications with Capistrano
Almir Mendes
 
PPTX
Pynvme introduction
Crane Chu
 
PDF
Ansible 202 - sysarmy
Sebastian Montini
 
PPTX
Rails 勉強会#3
masami ito
 
Scaling python webapps from 0 to 50 million users - A top-down approach
Jinal Jhaveri
 
Scheduling torque-maui-tutorial
Santosh Kumar
 
Ansible lightning talk at Scale 12
Justin Garrison
 
Rapid tests development
The Software House
 
Ansible 202
Sebastian Montini
 
Elasticsearch (R)Evolution — You Know, for Search… by Philipp Krenn at Big Da...
Big Data Spain
 
Ac cuda c_1
Josh Wyatt
 
Sup intro
chase pettet
 
Use of django at jolt online v3
Jaime Buelta
 
DJUGL - Django and AWS Lambda
Malcolm Box
 
Event Loop in Javascript
DiptiGandhi4
 
Scaling with Python: SF Python Meetup, September 2017
Varun Varma
 
New Ways to Find Latency in Linux Using Tracing
ScyllaDB
 
Deploying Rails Applications with Capistrano
Almir Mendes
 
Pynvme introduction
Crane Chu
 
Ansible 202 - sysarmy
Sebastian Montini
 
Rails 勉強会#3
masami ito
 
Ad

Similar to Simple Tips and Tricks with Ansible (20)

PDF
Ansible 101 - Presentation at Ansible STL Meetup
Jeff Geerling
 
PPT
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltStack
 
PPTX
Automating with ansible (Part A)
iman darabi
 
PPTX
Automating with Ansible
Ricardo Schmidt
 
PDF
Webinar: Automate IBM Connections Installations and more
panagenda
 
PDF
Automating with ansible (part a)
iman darabi
 
PPTX
Using Ansible Dynamic Inventory with Amazon EC2
Brian Schott
 
PDF
Ansible not only for Dummies
Łukasz Proszek
 
PDF
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
PDF
A tour of Ansible
DevOps Ltd.
 
PPTX
Toolbox of a Ruby Team
Arto Artnik
 
PDF
Ansible loves Python, Python Philadelphia meetup
Greg DeKoenigsberg
 
PDF
IT Automation with Ansible
Rayed Alrashed
 
PDF
Introducing Ansible
Francesco Pantano
 
PDF
DevOps(4) : Ansible(2) - (MOSG)
Soshi Nemoto
 
PPTX
Deployment with Fabric
andymccurdy
 
ODP
Linux Cluster Job Management Systems (SGE)
anandvaidya
 
PPT
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
addame
 
PDF
Ansible at work
Bas Meijer
 
PDF
Ansible 2.0 spblug
Konstantin Novakovksy
 
Ansible 101 - Presentation at Ansible STL Meetup
Jeff Geerling
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltStack
 
Automating with ansible (Part A)
iman darabi
 
Automating with Ansible
Ricardo Schmidt
 
Webinar: Automate IBM Connections Installations and more
panagenda
 
Automating with ansible (part a)
iman darabi
 
Using Ansible Dynamic Inventory with Amazon EC2
Brian Schott
 
Ansible not only for Dummies
Łukasz Proszek
 
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
A tour of Ansible
DevOps Ltd.
 
Toolbox of a Ruby Team
Arto Artnik
 
Ansible loves Python, Python Philadelphia meetup
Greg DeKoenigsberg
 
IT Automation with Ansible
Rayed Alrashed
 
Introducing Ansible
Francesco Pantano
 
DevOps(4) : Ansible(2) - (MOSG)
Soshi Nemoto
 
Deployment with Fabric
andymccurdy
 
Linux Cluster Job Management Systems (SGE)
anandvaidya
 
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
addame
 
Ansible at work
Bas Meijer
 
Ansible 2.0 spblug
Konstantin Novakovksy
 
Ad

More from Keith Resar (7)

PDF
Rotating Passwords With Ansible and HashiVault
Keith Resar
 
PPTX
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Keith Resar
 
PPTX
Hosting For Your Startup, Side Project, or Big Dollar App - Minnebar 12
Keith Resar
 
PDF
Advanced Use of jinja2 for Templates
Keith Resar
 
PPTX
DevFestMN 2017 - Learning Docker and Kubernetes with Openshift
Keith Resar
 
PDF
Container Storage Best Practices in 2017
Keith Resar
 
PDF
Importing Code and Existing Containers to OpenShift - Minneapolis Docker Meet...
Keith Resar
 
Rotating Passwords With Ansible and HashiVault
Keith Resar
 
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Keith Resar
 
Hosting For Your Startup, Side Project, or Big Dollar App - Minnebar 12
Keith Resar
 
Advanced Use of jinja2 for Templates
Keith Resar
 
DevFestMN 2017 - Learning Docker and Kubernetes with Openshift
Keith Resar
 
Container Storage Best Practices in 2017
Keith Resar
 
Importing Code and Existing Containers to OpenShift - Minneapolis Docker Meet...
Keith Resar
 

Recently uploaded (20)

PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Software Development Methodologies in 2025
KodekX
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Doc9.....................................
SofiaCollazos
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 

Simple Tips and Tricks with Ansible

  • 3. @KeithResar Automating F5 Load Balancers Automating your F5 Local traffic managers using Ansible. Ready to run your first playbook? Come and see what F5 Networks has been up to with ansible playbooks. We will discuss and demo all the cool things you can automate on your BIG-IP. ...presented on June 21st
  • 7. Mike Dahlgren - [email protected] Now for the Tips and Tricks
  • 9. PARALLELISM AND STRATEGIES COMMANDS Number of forks can easily be defined with -f (default is 5) $ ansible webservers -a "/sbin/reboot" -f 10 Strategies can be used to control play execution an can be changed • Lineary strategy = in order execution (Default) • Free strategy = finish as fast as you can - hosts: all strategy: free tasks: ...
  • 10. Removing Files & Directories
  • 11. Removing a file from a server Easy for one File: $ ansible webservers -m file -a "dest=/path/to/file state=absent"
  • 12. Removing all the files and directory - name: remove files and directories file: state: "{{ item }}" path: "/srv/deleteme/" owner: 1000 # set your owner, group, and mode group: 1000 mode: '0777' with_items: - absent - directory
  • 14. Set Defaults in a custom Ansible configuration file. • No need to type -i myhosts from the CLI • Remove the useless .retry files • Can be used anywhere you run Ansible Precedence model: * ANSIBLE_CONFIG (an environment variable) * ansible.cfg (in the current directory) * .ansible.cfg (in the home directory) * /etc/ansible/ansible.cfg
  • 16. TIME LIMITING BACKGROUND OPERATIONS Run script in background (30 Min timeout) $ ansible webserver -B 3600 -P 0 -a "/bin/long_cmd --do-stuff" Checking on the status of a previous job $ ansible web1.example.com -m async_status -a "jid=488359678239.2844" We can set how often to poll the status (60 seconds) $ ansible webserver -B 1800 -P 60 -a "/bin/long_cmd --do-stuff"
  • 17. Clean up your debugging tasks
  • 18. Clean up your debugging tasks - debug: msg: "This always displays" - debug: msg: "This only displays with ansible-playbook -vv+" verbosity: 2
  • 20. Don’t just start services -- use smoke tests - name: check for proper response uri: url: http://localhost/myapp return_content: yes register: result until: '"Hello World" in result.content' retries: 10 delay: 1
  • 22. Use patterns quickly and effectively - Continued Wildcards work one*.com:dbservers So can Regex ~(web|db).*.example.com But would this work? www[01:50].example.com, db-[a:f].example.com
  • 24. Moving Drive letters in a Puppet Manifest vars: alphabet: "abcdefghijklmnopqrstuvwxyz" tasks: - block: - name: change disk names replace: path: /etc/puppet/example/{{ hostname }}.yaml regexp: 'sd{{ alphabet[item | int + 1] }}' replace: 'sd{{ alphabet[item | int] }}' with_sequence: start=0 end=11
  • 26. Flow Control in Templates {% for port in jmx_ports %} <Connection> ServiceURL "service:jmx:rmi:///jndi/rmi://{{ inventory_hostname }}.example.com:{{ port }}/jmxrmi" Host "{{ inventory_hostname }}.example.com" InstancePrefix "port_{{ port }}" Collect "memory" Collect "threads" Collect "classes" </Connection> {% endfor %}
  • 27. TASK [command] ********************************* [WARNING]: Consider using yum module rather than running yum changed: [localhost] @KeithResar
  • 28. - hosts: all tasks: - command: yum -y install telnet - yum: name=telnet state=present - command: yum -y install telnet args: warn: False @KeithResar
  • 29. What is your favorite Trick?