SlideShare a Scribd company logo
1 of 25
Download to read offline
How to drive
your
webservices
with Ansible
Some context
3
What we tried to resolve
● Need a way to interact with our resources
● Should be easily readable by a non-developer audience
● We don’t want to do some shell scripting on top of our CLI
Why Ansible?
Ansible was already popular in the team
● We use it to manage the production environment
● Well integrated in our CI/CD chain
Our users were already
● Familiar with it
● Or willing to learn
Lingua franca internally for the deployment of the product deployment
● Ceph-Ansible
● OpenShift-Ansible
● etc
So we will prepare our own modules
But! The uri module already does that?!
- name: Create a JIRA issue
uri:
url: https://your.jira.example.com/rest/api/2/issue/
method: POST
user: your_username
password: your_pass
body: "{{ lookup('file','issue.json') }}"
force_basic_auth: yes
status_code: 201
body_format: json
uri was not an option (1/2)
● Authentication layer
○ We use AWS Signature Version 4
uri was not an option (2/2)
● Authentication layer
○ We use AWS Signature Version 4
● Imply boilerplate code
○ to handle errors
○ format some parameters
● ...
Our final current technical stack
Web UI
REST API
Control Server
Ansible modules CLI
Python library
Ansible
playbook
Our final current technical stack
Web UI
REST API
Control Server
Ansible modules CLI
Python library
Ansible
playbook
Our API
● Very generic REST API
● 10 =~ resources
● We use the standard REST verbs
Our API: list
GET http://srv/api/v1/roles
Our API: list
POST http://srv/api/v1/roles
Content-Type: application/json
{
“Name“: “boby”
}
Our API: get
GET http://srv/api/v1/roles/$foo
Our API: delete
DELETE http://srv/api/v1/roles/$foo
From Ansible
You can adjust your ansible.cfg to include another module directory (library). e.g:
[defaults]
library = /usr/share/dci/modules/
Python code sample
def main():
resource_argument_spec = dict(
(blabla)
)
resource_argument_spec.update(authentication_argument_spec())
module = AnsibleModule(
argument_spec=resource_argument_spec,
required_if=[['state', 'absent', ['id']]]
)
context = build_dci_context(module)
action_name = get_standard_action(module.params)
role = DciRole(module.params)
action_func = getattr(role, 'do_%s' % action_name)
http_response = run_action_func(action_func, context, module)
result = parse_http_response(http_response, dci_role, context, module)
module.exit_json(**result)
How to share code between modules?
If you have several modules like us, you may want to share some code between them. The
module_utils directory can be handle:
[defaults]
library = /usr/share/dci/modules/
module_utils = /usr/share/dci/module_utils/
How to share code between modules?
In our case, we share a dci_common.py for:
● Error handling
● Boilerplate for the different actions (delete, list, get, update, etc)
● Authentication
● And argument parsing
Idempotence
Reentrancy is import (much like a regular playbook)
You should be able to rerun the same module with the same parameters.
Documentation
Ansible-doc will read your module documentation.
https://docs.ansible.com/ansible/2.7/dev_guide/developing_modules_documenting.html
Testing (1/2)
● Hard to do unit-testing
○ We actually gave up
● We redeploy an testing environment
○ Molecule is not an option AFAIK
● “Unit-testing” through a series of task/assert
○ more like integration testing with a limited scope
● Functional testing
○ A playbook to
○ Serie of playbook

More Related Content

What's hot

Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
Nerd Tzanetopoulos
 

What's hot (20)

Redmine Betabeers SVQ
Redmine Betabeers SVQRedmine Betabeers SVQ
Redmine Betabeers SVQ
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 
Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2
 
URI handlers
URI handlersURI handlers
URI handlers
 
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
 
How to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter KriensHow to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter Kriens
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework Application
 
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4
 
Elixir と Maru で REST API
Elixir と Maru で REST APIElixir と Maru で REST API
Elixir と Maru で REST API
 
routes.rb をもう一度考えてみた #shibuyarb
routes.rb をもう一度考えてみた #shibuyarbroutes.rb をもう一度考えてみた #shibuyarb
routes.rb をもう一度考えてみた #shibuyarb
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 

Similar to How to driver your webservices with ansible

Similar to How to driver your webservices with ansible (20)

Gohan
GohanGohan
Gohan
 
Migrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mindMigrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mind
 
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John Hardy
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Introduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud RunIntroduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud Run
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Creating a modern web application using Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform AtlantaCreating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using Symfony API Platform Atlanta
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Into The Box | Alexa and ColdBox Api's
Into The Box | Alexa and ColdBox Api'sInto The Box | Alexa and ColdBox Api's
Into The Box | Alexa and ColdBox Api's
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
RESTful API-centric Universe
RESTful API-centric UniverseRESTful API-centric Universe
RESTful API-centric Universe
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
 

More from Gonéri Le Bouder

High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...
Gonéri Le Bouder
 
Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011
Gonéri Le Bouder
 

More from Gonéri Le Bouder (20)

Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdfRed Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
 
How to speed up your (API client) modules
How to speed up your (API client) modulesHow to speed up your (API client) modules
How to speed up your (API client) modules
 
Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02
 
Ansible meetup - Québec - april 25th, 2019
Ansible meetup - Québec - april 25th, 2019Ansible meetup - Québec - april 25th, 2019
Ansible meetup - Québec - april 25th, 2019
 
Montreal ansible meetup april 17th, 2019
Montreal ansible meetup   april 17th, 2019Montreal ansible meetup   april 17th, 2019
Montreal ansible meetup april 17th, 2019
 
Distributed-CI - OpenStack Montréal - 2018-06
Distributed-CI - OpenStack Montréal - 2018-06Distributed-CI - OpenStack Montréal - 2018-06
Distributed-CI - OpenStack Montréal - 2018-06
 
DCI presentation during OpenStack Montréal - 2018-06
DCI presentation during OpenStack Montréal - 2018-06DCI presentation during OpenStack Montréal - 2018-06
DCI presentation during OpenStack Montréal - 2018-06
 
Python + ansible = ♥
Python + ansible = ♥Python + ansible = ♥
Python + ansible = ♥
 
How to use TripleO tools for your own project
How to use TripleO tools for your own projectHow to use TripleO tools for your own project
How to use TripleO tools for your own project
 
Fusioninventory journees-perl-2012
Fusioninventory journees-perl-2012Fusioninventory journees-perl-2012
Fusioninventory journees-perl-2012
 
Otrs help desk-solutions-linux-2012
Otrs help desk-solutions-linux-2012Otrs help desk-solutions-linux-2012
Otrs help desk-solutions-linux-2012
 
Fusioninventory openworldforum-paris-2011-september
Fusioninventory openworldforum-paris-2011-septemberFusioninventory openworldforum-paris-2011-september
Fusioninventory openworldforum-paris-2011-september
 
GLPI RMLL-2011
GLPI RMLL-2011GLPI RMLL-2011
GLPI RMLL-2011
 
Fusioninventory rmll-2011
Fusioninventory rmll-2011Fusioninventory rmll-2011
Fusioninventory rmll-2011
 
Linuxtag 2011-it-asset-management-glpi-fusioninventory
Linuxtag 2011-it-asset-management-glpi-fusioninventoryLinuxtag 2011-it-asset-management-glpi-fusioninventory
Linuxtag 2011-it-asset-management-glpi-fusioninventory
 
High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...
 
Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011
 
Fusioninventory 2010-french
Fusioninventory 2010-frenchFusioninventory 2010-french
Fusioninventory 2010-french
 
Fusioninventory froscamp2010
Fusioninventory froscamp2010Fusioninventory froscamp2010
Fusioninventory froscamp2010
 
présentation de Debian 2
présentation de Debian 2présentation de Debian 2
présentation de Debian 2
 

Recently uploaded

electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
benjamincojr
 
Microkernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemMicrokernel in Operating System | Operating System
Microkernel in Operating System | Operating System
Sampad Kar
 
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
Madan Karki
 

Recently uploaded (20)

Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligence
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
AI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdfAI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdf
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Microkernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemMicrokernel in Operating System | Operating System
Microkernel in Operating System | Operating System
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
 

How to driver your webservices with ansible

  • 3. 3
  • 4. What we tried to resolve ● Need a way to interact with our resources ● Should be easily readable by a non-developer audience ● We don’t want to do some shell scripting on top of our CLI
  • 5. Why Ansible? Ansible was already popular in the team ● We use it to manage the production environment ● Well integrated in our CI/CD chain Our users were already ● Familiar with it ● Or willing to learn Lingua franca internally for the deployment of the product deployment ● Ceph-Ansible ● OpenShift-Ansible ● etc
  • 6. So we will prepare our own modules
  • 7. But! The uri module already does that?! - name: Create a JIRA issue uri: url: https://your.jira.example.com/rest/api/2/issue/ method: POST user: your_username password: your_pass body: "{{ lookup('file','issue.json') }}" force_basic_auth: yes status_code: 201 body_format: json
  • 8. uri was not an option (1/2) ● Authentication layer ○ We use AWS Signature Version 4
  • 9.
  • 10.
  • 11. uri was not an option (2/2) ● Authentication layer ○ We use AWS Signature Version 4 ● Imply boilerplate code ○ to handle errors ○ format some parameters ● ...
  • 12. Our final current technical stack Web UI REST API Control Server Ansible modules CLI Python library Ansible playbook
  • 13. Our final current technical stack Web UI REST API Control Server Ansible modules CLI Python library Ansible playbook
  • 14. Our API ● Very generic REST API ● 10 =~ resources ● We use the standard REST verbs
  • 15. Our API: list GET http://srv/api/v1/roles
  • 16. Our API: list POST http://srv/api/v1/roles Content-Type: application/json { “Name“: “boby” }
  • 17. Our API: get GET http://srv/api/v1/roles/$foo
  • 18. Our API: delete DELETE http://srv/api/v1/roles/$foo
  • 19. From Ansible You can adjust your ansible.cfg to include another module directory (library). e.g: [defaults] library = /usr/share/dci/modules/
  • 20. Python code sample def main(): resource_argument_spec = dict( (blabla) ) resource_argument_spec.update(authentication_argument_spec()) module = AnsibleModule( argument_spec=resource_argument_spec, required_if=[['state', 'absent', ['id']]] ) context = build_dci_context(module) action_name = get_standard_action(module.params) role = DciRole(module.params) action_func = getattr(role, 'do_%s' % action_name) http_response = run_action_func(action_func, context, module) result = parse_http_response(http_response, dci_role, context, module) module.exit_json(**result)
  • 21. How to share code between modules? If you have several modules like us, you may want to share some code between them. The module_utils directory can be handle: [defaults] library = /usr/share/dci/modules/ module_utils = /usr/share/dci/module_utils/
  • 22. How to share code between modules? In our case, we share a dci_common.py for: ● Error handling ● Boilerplate for the different actions (delete, list, get, update, etc) ● Authentication ● And argument parsing
  • 23. Idempotence Reentrancy is import (much like a regular playbook) You should be able to rerun the same module with the same parameters.
  • 24. Documentation Ansible-doc will read your module documentation. https://docs.ansible.com/ansible/2.7/dev_guide/developing_modules_documenting.html
  • 25. Testing (1/2) ● Hard to do unit-testing ○ We actually gave up ● We redeploy an testing environment ○ Molecule is not an option AFAIK ● “Unit-testing” through a series of task/assert ○ more like integration testing with a limited scope ● Functional testing ○ A playbook to ○ Serie of playbook