Add to Watchlist

Extending and embedding Ansible with Python


Citation of segment
Embed Code
Purchasing a DVD Cite video

Automated Media Analysis

Recognized Entities
Speech transcript
both the morning and relying on in English and about the me introduce to problem grows is going to do this and so on and so that was saying and and the number nodes in the dimension of the of the of the meaning of this is going so that's why it that the reason by the time the today I'm going to about extending and many it's about what please the gradient and any 1 you we have used and what we hello and I'll have everything that's the right time talking 1 of the people that the media and then I'll continue explaining how have do I how do you do with leverages improvements an integration with which is the product of the extending and that that is the introduction of the 1 0 1
1 2 0 what sensibilities it's our configuration management tools you maybe know anything many of those tools themselves with others and share their results that have sea of engine what the basic idea is to be able to automate the configuration of the whole and by host I mean little machines that they're made containers everything can be managed and so what if there are many alternatives and basically the strong points of the that it works over ssh out of the the box NET state unless that means that you do not have to install anything in the whole system apart from the to the next and another very strong point is that it is quite readable and it has smooth so that the learning curve it's not steep because it's it's the Israelis language is general based so it's quite readable and it's easy varies this get on and started so this could be example of uh and and civil architecture in which there is
essentially call management known all over control which could be an actor could be a server which you around the sensible then you also have some inventory files that describe the IPC and DNS names of the host and the groups of the whole that you're managing and then there the host which are remote machines that can be accessed over stage and there are a series of labels that are like the script that said the answer will machine executes in 2 of the hose that these and so this could be a very basic was
filed in which we define 2 group of 7 as 1 of web and out of the service we can define the arrival of that of the common to all the robot service for example we use the name of the TV group and we can define metagroups that group and other groups like his 1 which is structure on the that's a joint into whatever and that 2 ways to use as well basically there are other comments on using playbooks so what comments is very is this way the so what that everyone that and that gets a throwaway 110 executions in which you use the uncivil comments in order to execute a model in the group of posts and this index is very simple to use you civil name of the group as described in your inventory file minus m name of the module and minus cited the absence this could be the Hello world that everyone has a it with using this model called being that's was the only thing that does is respond with a path in the server so it's to assuming all minus being and only some magical group and that groups everything in the in the interest of then it would have different forms in each 1 of the servers to we would have been that this bond and also there a value that states that there it that States if anything has changed in the remote host and the other way is to do you sensible ways to use things and they will are much more struc to wait to do computation management that basically demo files that specify a list of places and his plays a series of tests that are applied to a group of each 1 of those that use an execution of ammonia with some parameters and description this could be 1 1 task that is ensuring that the in any engine server started this description this is the model name and all the other parameters saying that the service is engine and the state we decide to use started this is an example of cooperation management concept that is that we define the desired states and not the actions to be performed so that this model is year clever enough to know that it made it sometimes it has to start the service and sometimes just make a new world and this could be a to the
going into next display we're targeting the group opposed name whether we defined some variety and this is the list of the presidency their models to other repositories maybe the repositories models to instill so maybe packets a modest amount of services models to create or remove 5 in this case 2 were moving and that's the same length as the model to simply tell things like uh ginger to to replace the government going to template out in the remote host and it also their handlers that's our special kind of tasks that are ones independently of the number of times that they have been notified during the the label so this could be the execution of the playbook we will have an output In that sequentially shows the results of the tests in each 1 of the host and finally there's a nice weekend just a few is a reduction in the weight to manage Cesar using uh kind of encapsulation that Israel's policies and little bit more advanced and concept in civil that yes is a group of arrivals of tasks of handlers Protestant in place and may even better is to other roles still the initial introduction I will be talking about how to hack sensible there 2 ways embedding and extending and civil so what raining embedded in calling and civil models and labels from your Python code and what this basically possible because I can pay and civil it's based on like and it's written right that so it has some kind of a vitamin D and it's not very well the connected by body it's quite easy to you and if you read the source you will have the there you will see how to use it although you can just there continue on and see how we use it in this presentation just before we start the disclaimers this code is valid for all of all the and the 9 which is the current state 1 burst into which is the current development 1 thinks of going to change the state yeah it's going to change and probably even things like the lack of a mechanism is going to change so this is only valid I can only guarantee that its value for the current stable version and what everything in a civil is likened to detect only it hasn't been ported to 3 and you can find examples in the in this did have a so the 1st thing that we may want to do we may want to run on a similar task is is a simple kind of automation is assessed calling a model from
your from urine civil code how do we do it very simple guest . some classes on basic around and inventory from the the article every you would you will by build your inventory for example directly encode with made just targeting all local host and then x in making an instance of writing and calling the run mode the random dispersing the modeling of the the arguments the inventory that we have just created and that pattern of holes that we are
we want tool target just Liu Bei's aerial this and talking about that what are the interval that actual facts our information that is retrieved at the beginning of the execution of the playbook each 1 of the hosts and this is bunch of information available for you to make things in the playbook so you have the host and IP addresses the hardware information the even be installed a
version of this sort of work so I'm going to make an example which is the flat factor in which this a proof of concept of the embedding of a model that I'm running a program that will create a REST API using the last full model in that it passes their euros in in this form a getting there are facts that we want to know about list to them and it will run the model to and then passed the data that we are showing that the fact now system it could be just the not very practical but it could be a uh an idea of how we can retrieve information from
from a remote server so here we are the In look course and
retrieved the version of the the software the and and I'm running of the version of the kind of seems a bit more complex like the network
card information so sometimes we need something more complex than an running a model we need some kind of orchestration so we may need to run and play book which is a more structured way so you have to put a little bit more or less is basically classes for all of us and you to you have to build during the tree it's similar to the other case in this case we also using our and a host of arrivals yeah because so in this example I'm going to attach some information to the inventor in the list of users and maybe but it's want to install and create you have to put some boilerplate code just to say that the velocity of the division of the plane of the table and also to reduce the because of call for the for the runner and the label and finally creating a playbook instant and a using model run a specified I the Babel in this case the playbook is there in the order of in this example of
what I'm going to move around
I'm going to write a playbook that and so there's some I think about and create some users because it said to be
contest when you arrive at a time so begin creating new services and selling installing suffered of this so I dont created of concept script in which the I guess 1st I get the interactive consul the information although the name of the users and the list of what it is and then there I call of the interval label which is calling other the DML and I passed the list of packages and used to support inventory of Bibles so that could be an example
of this kind of integration arrived can create and I can construct mortgages and when I finished it runs in local host and it has changed that and you we can show that although the current user Alex is created task done anything but for the new user that created it is called george has changed the system also selling and other so I have a cold and label from think 0 what
that is 1 way to I and civil
is by embedding and the weight is extended and singing and so and by extension mean adding more functionality or customizing behavior basically start by 3 ways creating models creating dynamic inventory scripts and create employment so let's start with creating an unstable model as it with tons of models ranging from pleading usernames they're managing databases spinning cloud server so sometimes we need something more the specific to our business and so we have to create a model on what is in civil model is just nexus executable file did you will find some folders and that of library their relative to your place or in the sensible library and basically hesitation interface so we'd expect adjacent for the input and also emits education for the output so it's language-agnostic even doing the best you can do in every language that you want but you using Python then it's easier because there are some code of functions that will make in the region this could be the example of this sort of a typical model borrowed some of us from the existing models and basically it's a file in which you have 2 strings will come later than that of their documentation and examples then this part of the of the of the goal these what I call the light on in plant in which the of the heart of what we call the libraries and we run out of this this logic and then From the point this is like templates that say in which we find main model we do
some instantiation of the the uncivil model class we call our family back from this from these from this function and then we admit said he different thing sticks to the depending on on the result
solar on Monday to a condition on examples are just strings variables that are
important because they are used by make what just to generate the question about the documentation and some of important parts of the addition of some particle which is specified the values of the arguments and it's important to keep in sync with the real cold which is their arguments that dictionary you just specified with a means to units something someone Python to be installing the controller and you have to use the notes section you need that some environmental environment of arrival for example is present at the controller and the examples just put cold these studies tested and 1 especially want to submit it to the possible repository In what happened the other they called on part yeah it's usually a good idea to put pure Python code in all the library so that you may need for dealing with the problem let's try not to use the uncivil part because it will make your code more robust to changes in the ensemble API however there are some of the functions for example is 1 of the from the possible model from them to the library there that there that allows you to easily run common and find executables in very remote machines which can get some teachers try to return the value of N a message a meaningful message in and code everything every information on those values and don't bring to stand output what Auroora because this mechanism 1 and in the main function you have to create an initial model instance and will begin to instantiate you Western arguments that dictionary which defined modular arguments defined a series of models that are required for the ones that are optional and default values possible choices alliances and then there's a section option in which is specified much exclusion of the parameters and also use park check out this mode in which you do I drive around and you know do not mess with the real system system so when you created that you magically have a dictionary crime in which you have the parameters of the implication of the of the model you have just to take those parameters called the pipeline in front of the module with those parameters and then because the results depending on the statutes and the message up to create some kind of data and if some actions like this 1 excitation and variations in your life will be easier because they are augmented everything and create a you and
finally you probably have seen ghost like at the end of the year and that of of the upright and stares you are probably you're not in 2 years and in pain because the as I found budget the board Ussery but these resist the temptation to make and if this is important because really it's like define a preprocessor and the because as will will substitute those lines with the code of the helper functions so you'll do not good at it 1 finding a new 1 company n if you do not put it at the end of the file it will change the line are and will be will be a 0 some Christian literature candidates to make them what you want to laughter
you'll love use model that is the template and that's supposed to take all this you model disability handy tool included that is the test model as script and they want to so make it a this fraudulent a model follow the money creation to place that is available online and it's much more comprehensive have created a model an example which is called the tag take set and agile paraded management system that has some API this electrical I can take that allows to match to the to play with it so I've created our the temple
model that's called take to this model is just for predicting each using this platform 1st of all we are developing a system that mandible and we find of some problems during the automation of the tasks we can create an issue so that the team will see it will have the information will have the last have everything so this year I have submitted to 1 Simple extra model repository and basically this is the documentation by you have to specify the different options that is the model and you have to put some examples this is what I call the electronic part time all the rights and tiger and I'll do that they used to management here should be that and finally this is the main wars in which we i specify the restrictions on the parameters of them and I call this type the 2 arguments and depending on the on the evidence that is you 1 kind of do some of the other
and if I if we see the playbook you can just use this model to create a database to in our project we can manage description within could also on civil rivals like the hostname and distribution we can attach to the issue of violence for example can that's the label and then I will post and when I continue it would that age because the model supports the state present and absent so the is the
test problem that I've created with now it seems and then verandaed doing because the answer will label of the label that we have seen that has run the creation of the tape goes through and it has stopped
if I take here that I can see the these you have some this is still my answer would
distribution and this is the this
is that there so the virus the
local and then deleted we must it's not so creating a
dynamic inventors screen this another way to have if you are managing that services without infrastructure quality you know about this in a dynamic inventors creates our way not to have to deal with their long is of service that probably aren't changing their ideas changing you can say it seems so dynamic inventories graves away to the deal with the complexity and basically there are just some lexical form of that supports the those common actually minus finally that would earn adjacent
dictionary whether the name of the groups and each group is a list of hope and minus minus cost in which you specify how name and then you get a dictionary of the host of arrivals just a few days and
so just for the fun of it as have created an example which is shelf inventory you know shell files in there are basically a key-value store and that I suppose natively in the serialization so they In the example we have just using our of the file that I have created and a with an open mind and the groups and the and host bars I can and
I get us through the general growth we
are in a lot of time I want to run out of the blends lighting so a way to height and civil in very different ways and basically the common thing is that the running the controller node and there are different kind of patterns we're going to see some of them and uh basically we tried it and thought them just about them in a folder and if you want to use manifold the just treat the answer config file so the collect blood instead this kind of like that reacts in the control to the label and run the events in order to create them ideas how to define a call model class and then overwrite method to 1 2 that's an example of a list of methods available for this class in the repository
so just a brief examples I'm going to be used to create a public plan that's reacts to the failed of the band of model and then called the 95 cent binary which will create a pop up in my system a with dell name of the model and the result of the model at each I'm running this
labeled we we just all want to the message the 1st chapter of all the the 2nd 1 in favor of by the end of the last thing in the 2nd 1 as far as just an example of things that can be done you can make statements applications and make set of new using useful
you can create connection and basically connection playing allows the controller to connect to the more remote host as simple as scholarships with lots of them but you can create so much more you just have your house you'll just have to define our connection classes and override the basic methods that just chain connecting disconnecting considered income putting an infected file which are basically the things that actually doing is a small you can create lookup Latin so that the variance allowed to expand the function of by setting existing information in there in
external sources from the controller for example in databases in systems and seeing that it's just at calling the lookup function and also if you define a look at your that out with a version that Pelosi you to look at all the summit of so they you just have to create a lookup model of classes and there basically is defined in any method and the random effect which will the terms which are divided in their function the argument of the lookup and then returns a list of the results is all in the Temple of the shell file icon and then define that as of 5 that that that will search for a show trial and return retrieve key from that shall file basically I guess the instrument the run the run method and this in addition
to all the i In this people I'm opening the book that the retrieving the book may enable a temple of the book and being now and print them In so the good will of the Russian government and until
you can create a filter light and food supply and starting date the and she will sheet with you it's just Newtons but you can define some of the air pollutants this and for using them Margaret is very simple variables followed by the
name of the those in example uses that there civil comes with them but you can find many many other is very simple discrete filter model classes and that have a future as a method that returns a mapping to a from the name of the field to the iconic functions that are
implemented in for example we can and create to rotate position so this is this is a rotation and just
if we see that as an example of playbook FIL and applied once and then applied to try and we can see that system becomes the entire thing and then becomes the so it's work finally
just other patterns very fast action plans that are outlined in this area that lower separation of functions between the controller and you remove host for example when you're there completing out of 5 there some actions that need to be performing the controller and some other big difference in the remote so that you can just implement Annex a model of a class with a method ground and when you're dealing doing things in the control and you will execute this method runner execute model to call the real model and the remote host and defined by explains why the undocumented but possibly going to change the sensible mission to and is the ways that we can retrieve more information about the holes by some external source like the house lots and group lots
directory basically this is something that you will find in the report and you have to implement get host bias and get group 5 for a
new plant became greatest leptons very modern their functionality from its evolution . 1 1 take in which we can retrieve the information of holes have not going to be conducted in the current based label in yes using a back-end like a radius or in cash you can run once you get the facts and then runs without having to retrieve the facts of the rest of the holds have to keep your so of the because of and basically you create a new 1 you want to to create new you just have to implementing this template and finally because of the references that I have used a very good book but not just for things possible idea for you in especially devoted to what is happening logic close talking about that so that's it thank you very much and now you have any questions such that the which can be any questions and 1 of thanks for the detecting and my question is you mention that uh was using Constable costs and that the model is very hard to find the condition of maybe I or is it very poorly documented sold actually come like get this information use of standard model of if you are OK if you want to embed a model like in the 1st example of that I said that that have had to do some research I has to go into the source code and see how the common is using the idea and try to mimic it because we are using the same again that the command line version of the system by component is executed also I have seen some of other examples which are here in the reference that I have much more pragmatic examples so I have been inspired from them a I think that conversion to that's 0 they're going to document it much better they know all in and the eyes of operators that they're acting on the condition that part I don't know if intentionally the selection of it and it's changing 1 and similar to 0 the colonists there there's a table of properly and it will have a chance to say it's not going to be I think it's not so simple but uh more
flexible the that but that wasn't the way of testing my used to you need to write this in some specific language like or libraries this is called last time this was some well the same things and so it's quite pretty intragastric because even the uncivil called base is not very well covered with that you see the product there are just so like 100 and something assertions on the code so they're not very concerned about the testing and testing a model is even much more difficult I would suggest is used to test Pythonic part separately guess this kind of fun which is your life and you can use just as you can did the testing and other files but there's no understand the way to run programmatically tests to our model and didn't have even to make test good testing pull request to get the model except and they're not very strict with this but what I would suggest scene testing only these that signing by the business value of your model using an external library like my test something really that would mean that you have different file an important did they have to decide the lesson that you define so my theory so it's easier it's something like this picture like during the teacher has taken well with this intent you're not using you like I think it's a unit it's an all-out like uh uh and then made its funds to the testing of something like that to speech and just so this is like is it is it a little bit of it relief for protesting there of it OK the President of the I didn't know that it was possible to put to use should figure out how to any more questions OK if there are no more questions than please stand on them
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation


Formal Metadata

Title Extending and embedding Ansible with Python
Title of Series EuroPython 2015
Part Number 124
Number of Parts 173
Author Rodríguez, Alejandro Guirao
License CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
DOI 10.5446/20063
Publisher EuroPython
Release Date 2015
Language English
Production Place Bilbao, Euskadi, Spain

Content Metadata

Subject Area Information technology
Abstract Alejandro Guirao Rodríguez - Extending and embedding Ansible with Python [Ansible] is the new cool kid in town in the configuration management world. It is easy to learn, fast to setup and works great! In the first part of the talk, I will do a super-fast introduction to Ansible for the newcomers. If you are a Pythonista, you can hack and leverage Ansible in many ways. In the second part of the talk, I will describe some options to extend and embed Ansible with Python: - Embedding Ansible with the Python API - Extending Ansible: creating modules, dynamic inventory scripts and plugins Previous experience with Ansible is advised in order to get the most of this talk, but beginners to the tool will also get an overview of the capabilities of this kind of integration.
Keywords EuroPython Conference
EP 2015
EuroPython 2015

Related Material


AV-Portal 3.5.0 (cb7a58240982536f976b3fae0db2d7d34ae7e46b)


  599 ms - page object