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
PDF
Traceur - Javascript.next - Now! RheinmainJS April 14th
PDF
Ansible party in the [Google] clouds
PDF
What's new in Ansible 2.0
PPTX
Gearman & PHP
PPTX
Web development-workflow
PDF
Ansible
PPTX
Jk rubyslava 25
Rubyslava + PyVo #48
Traceur - Javascript.next - Now! RheinmainJS April 14th
Ansible party in the [Google] clouds
What's new in Ansible 2.0
Gearman & PHP
Web development-workflow
Ansible
Jk rubyslava 25

What's hot (19)

PPTX
Scaling python webapps from 0 to 50 million users - A top-down approach
PPTX
Scheduling torque-maui-tutorial
PPTX
Ansible lightning talk at Scale 12
PDF
Rapid tests development
PDF
Ansible 202
PDF
Elasticsearch (R)Evolution — You Know, for Search… by Philipp Krenn at Big Da...
PPTX
Ac cuda c_1
PDF
Sup intro
ODP
Use of django at jolt online v3
PPTX
DJUGL - Django and AWS Lambda
ODP
Event Loop in Javascript
PPTX
Scaling with Python: SF Python Meetup, September 2017
PDF
New Ways to Find Latency in Linux Using Tracing
PPTX
PDF
Deploying Rails Applications with Capistrano
PPTX
Pynvme introduction
PDF
Ansible 202 - sysarmy
PPTX
Rails 勉強会#3
Scaling python webapps from 0 to 50 million users - A top-down approach
Scheduling torque-maui-tutorial
Ansible lightning talk at Scale 12
Rapid tests development
Ansible 202
Elasticsearch (R)Evolution — You Know, for Search… by Philipp Krenn at Big Da...
Ac cuda c_1
Sup intro
Use of django at jolt online v3
DJUGL - Django and AWS Lambda
Event Loop in Javascript
Scaling with Python: SF Python Meetup, September 2017
New Ways to Find Latency in Linux Using Tracing
Deploying Rails Applications with Capistrano
Pynvme introduction
Ansible 202 - sysarmy
Rails 勉強会#3
Ad

Similar to Simple Tips and Tricks with Ansible (20)

PDF
Ansible 101 - Presentation at Ansible STL Meetup
PPT
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
PPTX
Automating with ansible (Part A)
PPTX
Automating with Ansible
PDF
Webinar: Automate IBM Connections Installations and more
PDF
Automating with ansible (part a)
PPTX
Using Ansible Dynamic Inventory with Amazon EC2
PDF
Ansible not only for Dummies
PDF
Zero Downtime Deployment with Ansible
PDF
A tour of Ansible
PPTX
Toolbox of a Ruby Team
PDF
Ansible loves Python, Python Philadelphia meetup
PDF
IT Automation with Ansible
PDF
Introducing Ansible
PDF
DevOps(4) : Ansible(2) - (MOSG)
PPTX
Deployment with Fabric
ODP
Linux Cluster Job Management Systems (SGE)
PPT
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
PDF
Ansible at work
PDF
Ansible 2.0 spblug
Ansible 101 - Presentation at Ansible STL Meetup
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
Automating with ansible (Part A)
Automating with Ansible
Webinar: Automate IBM Connections Installations and more
Automating with ansible (part a)
Using Ansible Dynamic Inventory with Amazon EC2
Ansible not only for Dummies
Zero Downtime Deployment with Ansible
A tour of Ansible
Toolbox of a Ruby Team
Ansible loves Python, Python Philadelphia meetup
IT Automation with Ansible
Introducing Ansible
DevOps(4) : Ansible(2) - (MOSG)
Deployment with Fabric
Linux Cluster Job Management Systems (SGE)
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
Ansible at work
Ansible 2.0 spblug
Ad

More from Keith Resar (7)

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

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
August Patch Tuesday
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation theory and applications.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Mushroom cultivation and it's methods.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
1. Introduction to Computer Programming.pptx
August Patch Tuesday
Group 1 Presentation -Planning and Decision Making .pptx
Enhancing emotion recognition model for a student engagement use case through...
TLE Review Electricity (Electricity).pptx
Chapter 5: Probability Theory and Statistics
Hindi spoken digit analysis for native and non-native speakers
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
A Presentation on Artificial Intelligence
Encapsulation theory and applications.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
DP Operators-handbook-extract for the Mautical Institute
cloud_computing_Infrastucture_as_cloud_p
Mushroom cultivation and it's methods.pdf
WOOl fibre morphology and structure.pdf for textiles
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf

Simple Tips and Tricks with Ansible

  • 1. Mike Dahlgren - miked@redhat.com Tips and Tricks
  • 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 - miked@redhat.com 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?