SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Dernier (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

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