SlideShare a Scribd company logo
1 of 29
Download to read offline
Ansible Python
Greg DeKoenigsberg
Director, Ansible Community, Red Hat
@gregdek
Q+A
“Why are you starting with Q+A?”
What is Ansible, anyway?
“Isn’t it just distributed ssh?”
“Well, yes. Basically.”
“But it’s a lot more than that, too.”
Ansible is:
Distributed ssh
Plus a simple definition language
Plus hundreds of modules
Here’s a simple Ansible inventory.
mail.example.com
[webservers]
foo.example.com
bar.example.com
www[01:50].example.com
[dbservers]
db[a:f].example.com
[webservers:vars]
proxy=proxy.example.com
Here are some simple Ansible commands.
$ ansible webservers -a "/sbin/reboot"
$ ansible webservers -m command -a "/sbin/reboot"
$ ansible webservers -m command -a "/sbin/reboot" -f 10
Here’s a simple Ansible playbook.
---
- hosts: webservers
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: name=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
- hosts: databases
remote_user: root
tasks:
- name: ensure postgresql is at the latest version
yum: name=postgresql state=latest
- name: ensure that postgresql is started
service: name=postgresql state=started
So what is Ansible actually doing?
● Connects to the target systems simultaneously
○ One ssh connection per host, up to fork limit
● Copies over Ansible and all necessary module code
● Runs setup.py to assess the system state
● Runs through each individual play
○ Plays invoke module code, which is (almost always) Python
○ Runs in parallel by default, one play at a time over all systems
● Does things, or not
● Gathers output and sends back over ssh
● Removes itself when it’s finished!
○ (which is why we call Ansible “agentless”)
Oh btw, “state” is kind of a big deal in
configuration management tools.
Old school sysadmin tool: bash
“Here’s a list of commands. Do exactly what I tell you to do.”
New school sysadmin tool: ansible
“Here’s a description of a desired system state. Do as little as
possible to ensure that the system is in that state.”
(The cool kids call this “idempotence”, but no one seems to
agree on how to pronounce that word.)
You can’t set a system to a desired state without knowing the
system’s current state.
That’s why Ansible does “fact gathering” before every run,
using the “setup” module.
Modules can look at facts, and they can also talk to the target
host directly, to figure out state before taking action.
Here’s a simple Ansible module.
$ cat cloud/atomic/atomic_host.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public licenses
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18
19 ANSIBLE_METADATA = {'status': ['preview'],
20 'supported_by': 'community',
21 'version': '1.0'}
23 DOCUMENTATION='''
24 ---
25 module: atomic_host
26 short_description: Manage the atomic host platform
27 description:
28 - Manage the atomic host platform
29 - Rebooting of Atomic host platform should be done outside this module
30 version_added: "2.2"
31 author: "Saravanan KR @krsacme"
32 notes:
33 - Host should be an atomic platform (verified by existence of '/run/ostree-booted'
file)
34 requirements:
35 - atomic
36 - "python >= 2.6"
37 options:
38 revision:
39 description:
40 - The version number of the atomic host to be deployed. Providing
C(latest) will upgrade to the latest available version.
41 required: false
42 default: latest
43 aliases: ["version"]
44 '''
46 EXAMPLES = '''
47
48 # Upgrade the atomic host platform to the latest version (atomic host
upgrade)
49 - atomic_host:
50 revision: latest
51
52 # Deploy a specific revision as the atomic host (atomic host deploy
23.130)
53 - atomic_host:
54 revision: 23.130
55 '''
56
57 RETURN = '''
58 msg:
59 description: The command standard output
60 returned: always
61 type: string
62 sample: 'Already on latest'
63 '''
65 def core(module):
66 revision = module.params['revision']
67 args = []
68
69 module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSA
GES='C')
70
71 if revision == 'latest':
72 args = ['atomic', 'host', 'upgrade']
73 else:
74 args = ['atomic', 'host', 'deploy', revision]
75
76 out = {}
77 err = {}
78 rc = 0
79
80 rc, out, err = module.run_command(args, check_rc=False)
81
82 if rc == 77 and revision == 'latest':
83 module.exit_json(msg="Already on latest", changed=False)
84 elif rc != 0:
85 module.fail_json(rc=rc, msg=err)
86 else:
87 module.exit_json(msg=out, changed=True)
90 def main():
91 module = AnsibleModule(
92 argument_spec = dict(
93 revision = dict(default='latest', required=False, aliases=["version"]),
94 ),
95 )
96
97 # Verify that the platform is atomic host
98 if not os.path.exists("/run/ostree-booted"):
99 module.fail_json(msg="Module atomic_host is applicable for Atomic Host
Platforms only")
100
101 try:
102 core(module)
103 except Exception as e:
104 module.fail_json(msg=str(e))
105
106
107 # import module snippets
108 from ansible.module_utils.basic import *
109 if __name__ == '__main__':
110 main()
Ansible is “kind of a big deal” in Python-land
As in, it’s the largest project in contributors on GitHub.
By a lot.
As of 2/22/17, Ansible has 2,549 contributors.
Why does Ansible have so many contributors?
● Because the architecture is highly modular
● Because there are lots of examples to cargo cult
● Because the docs and guidelines are “good enough”
● Because GitHub provides common participatory infrastructure
● Because Python is an awesome language that’s easy to learn
● Because our community matters to us
Join the Ansible Philadelphia meetup!
Kickoff meeting, Thursday March 23rd:
https://www.meetup.com/Ansible-Philadelphia/
Thanks! / Q+A again / Story Time
@gregdek
greg@ansible.com

More Related Content

What's hot

Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Brian Schott
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done rightDan Vaida
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationKumar Y
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansiblejtyr
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?shirou wakayama
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansibleKhizer Naeem
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestrationbcoca
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
V2 and beyond
V2 and beyondV2 and beyond
V2 and beyondjimi-c
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopLorin Hochstein
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點William Yeh
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginnersKuo-Le Mei
 

What's hot (20)

Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansible
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
V2 and beyond
V2 and beyondV2 and beyond
V2 and beyond
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
Ansible - Crash course
Ansible - Crash courseAnsible - Crash course
Ansible - Crash course
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginners
 

Similar to Ansible loves Python, Python Philadelphia meetup

Ansible with oci
Ansible with ociAnsible with oci
Ansible with ociDonghuKIM2
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
Ansible not only for Dummies
Ansible not only for DummiesAnsible not only for Dummies
Ansible not only for DummiesŁukasz Proszek
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefMatt Ray
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Carlos Sanchez
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleBrian Hogan
 
Ansible & Salt - Vincent Boon
Ansible & Salt - Vincent BoonAnsible & Salt - Vincent Boon
Ansible & Salt - Vincent BoonMyNOG
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmusBram Vogelaar
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012Carlos Sanchez
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 
Ansible automation tool with modules
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modulesmohamedmoharam
 
Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdfNigussMehari4
 

Similar to Ansible loves Python, Python Philadelphia meetup (20)

Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with oci
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
Ansible not only for Dummies
Ansible not only for DummiesAnsible not only for Dummies
Ansible not only for Dummies
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and Chef
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
 
Ansible & Salt - Vincent Boon
Ansible & Salt - Vincent BoonAnsible & Salt - Vincent Boon
Ansible & Salt - Vincent Boon
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Testing Terraform
Testing TerraformTesting Terraform
Testing Terraform
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Ansible automation tool with modules
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modules
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
Puppet
PuppetPuppet
Puppet
 

More from Greg DeKoenigsberg

Community building lessons from Ansible
Community building lessons from AnsibleCommunity building lessons from Ansible
Community building lessons from AnsibleGreg DeKoenigsberg
 
AWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NC
AWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NCAWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NC
AWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NCGreg DeKoenigsberg
 

More from Greg DeKoenigsberg (6)

Ansible Case Studies
Ansible Case StudiesAnsible Case Studies
Ansible Case Studies
 
Community building lessons from Ansible
Community building lessons from AnsibleCommunity building lessons from Ansible
Community building lessons from Ansible
 
AWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NC
AWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NCAWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NC
AWS and Open Cloud, All Things Open, 10/25/2013, Raleigh NC
 
Gregdek @ EucaDay NYC
Gregdek @ EucaDay NYCGregdek @ EucaDay NYC
Gregdek @ EucaDay NYC
 
Tim Cramer, Eucaday
Tim Cramer, EucadayTim Cramer, Eucaday
Tim Cramer, Eucaday
 
Eucalyptus eucaday 201204_mgm
Eucalyptus eucaday 201204_mgmEucalyptus eucaday 201204_mgm
Eucalyptus eucaday 201204_mgm
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Ansible loves Python, Python Philadelphia meetup

  • 1. Ansible Python Greg DeKoenigsberg Director, Ansible Community, Red Hat @gregdek
  • 2. Q+A “Why are you starting with Q+A?”
  • 3. What is Ansible, anyway? “Isn’t it just distributed ssh?”
  • 5. “But it’s a lot more than that, too.”
  • 6. Ansible is: Distributed ssh Plus a simple definition language Plus hundreds of modules
  • 7. Here’s a simple Ansible inventory.
  • 9. Here are some simple Ansible commands.
  • 10. $ ansible webservers -a "/sbin/reboot"
  • 11. $ ansible webservers -m command -a "/sbin/reboot"
  • 12. $ ansible webservers -m command -a "/sbin/reboot" -f 10
  • 13. Here’s a simple Ansible playbook.
  • 14. --- - hosts: webservers remote_user: root tasks: - name: ensure apache is at the latest version yum: name=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf - hosts: databases remote_user: root tasks: - name: ensure postgresql is at the latest version yum: name=postgresql state=latest - name: ensure that postgresql is started service: name=postgresql state=started
  • 15. So what is Ansible actually doing? ● Connects to the target systems simultaneously ○ One ssh connection per host, up to fork limit ● Copies over Ansible and all necessary module code ● Runs setup.py to assess the system state ● Runs through each individual play ○ Plays invoke module code, which is (almost always) Python ○ Runs in parallel by default, one play at a time over all systems ● Does things, or not ● Gathers output and sends back over ssh ● Removes itself when it’s finished! ○ (which is why we call Ansible “agentless”)
  • 16. Oh btw, “state” is kind of a big deal in configuration management tools.
  • 17. Old school sysadmin tool: bash “Here’s a list of commands. Do exactly what I tell you to do.”
  • 18. New school sysadmin tool: ansible “Here’s a description of a desired system state. Do as little as possible to ensure that the system is in that state.” (The cool kids call this “idempotence”, but no one seems to agree on how to pronounce that word.)
  • 19. You can’t set a system to a desired state without knowing the system’s current state. That’s why Ansible does “fact gathering” before every run, using the “setup” module. Modules can look at facts, and they can also talk to the target host directly, to figure out state before taking action.
  • 20. Here’s a simple Ansible module. $ cat cloud/atomic/atomic_host.py
  • 21. 1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 4 # This file is part of Ansible 5 # 6 # Ansible is free software: you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation, either version 3 of the License, or 9 # (at your option) any later version. 10 # 11 # Ansible is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public licenses 17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>. 18 19 ANSIBLE_METADATA = {'status': ['preview'], 20 'supported_by': 'community', 21 'version': '1.0'}
  • 22. 23 DOCUMENTATION=''' 24 --- 25 module: atomic_host 26 short_description: Manage the atomic host platform 27 description: 28 - Manage the atomic host platform 29 - Rebooting of Atomic host platform should be done outside this module 30 version_added: "2.2" 31 author: "Saravanan KR @krsacme" 32 notes: 33 - Host should be an atomic platform (verified by existence of '/run/ostree-booted' file) 34 requirements: 35 - atomic 36 - "python >= 2.6" 37 options: 38 revision: 39 description: 40 - The version number of the atomic host to be deployed. Providing C(latest) will upgrade to the latest available version. 41 required: false 42 default: latest 43 aliases: ["version"] 44 '''
  • 23. 46 EXAMPLES = ''' 47 48 # Upgrade the atomic host platform to the latest version (atomic host upgrade) 49 - atomic_host: 50 revision: latest 51 52 # Deploy a specific revision as the atomic host (atomic host deploy 23.130) 53 - atomic_host: 54 revision: 23.130 55 ''' 56 57 RETURN = ''' 58 msg: 59 description: The command standard output 60 returned: always 61 type: string 62 sample: 'Already on latest' 63 '''
  • 24. 65 def core(module): 66 revision = module.params['revision'] 67 args = [] 68 69 module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSA GES='C') 70 71 if revision == 'latest': 72 args = ['atomic', 'host', 'upgrade'] 73 else: 74 args = ['atomic', 'host', 'deploy', revision] 75 76 out = {} 77 err = {} 78 rc = 0 79 80 rc, out, err = module.run_command(args, check_rc=False) 81 82 if rc == 77 and revision == 'latest': 83 module.exit_json(msg="Already on latest", changed=False) 84 elif rc != 0: 85 module.fail_json(rc=rc, msg=err) 86 else: 87 module.exit_json(msg=out, changed=True)
  • 25. 90 def main(): 91 module = AnsibleModule( 92 argument_spec = dict( 93 revision = dict(default='latest', required=False, aliases=["version"]), 94 ), 95 ) 96 97 # Verify that the platform is atomic host 98 if not os.path.exists("/run/ostree-booted"): 99 module.fail_json(msg="Module atomic_host is applicable for Atomic Host Platforms only") 100 101 try: 102 core(module) 103 except Exception as e: 104 module.fail_json(msg=str(e)) 105 106 107 # import module snippets 108 from ansible.module_utils.basic import * 109 if __name__ == '__main__': 110 main()
  • 26. Ansible is “kind of a big deal” in Python-land As in, it’s the largest project in contributors on GitHub. By a lot. As of 2/22/17, Ansible has 2,549 contributors.
  • 27. Why does Ansible have so many contributors? ● Because the architecture is highly modular ● Because there are lots of examples to cargo cult ● Because the docs and guidelines are “good enough” ● Because GitHub provides common participatory infrastructure ● Because Python is an awesome language that’s easy to learn ● Because our community matters to us
  • 28. Join the Ansible Philadelphia meetup! Kickoff meeting, Thursday March 23rd: https://www.meetup.com/Ansible-Philadelphia/
  • 29. Thanks! / Q+A again / Story Time @gregdek greg@ansible.com