Definitely an advanced feature of Ansible, but still good to know that it exists. And this variable can be made of other variables or strings. This lookup retrieves the value of an Ansible variable. Ansible registers are used when you want to capture the output of a task to a variable. The magic here is done by the vars-lookup plugin. The result is lookup('vars', item + '_' + stage + '_password') - this in turn gets interpolated to the actual password from my vault-file! In this lookup I look for vars that contain my item following the _-string, then the content of the variable stage (notice the missing curly braces here), finally the _password-string. This means that I first loop over all microservices (stored in the item-variable). This means I have nine different password-variables stored in an Ansible-vault encrypted file. The value of a task being executed in ansible can be saved in a variable and used later. Use of -v when executing playbooks will show possible values for the results. These credentials are different for every microservice in every stage. Another major use of variables is running a command and using the result of that command to save the result into a variable. Of course, every microservice needs to connect to a database using credentials. I also have a list of stages, called DEV, QA and PROD where the microservices get deployed to. The microservices are called foo, bar and baz. I have an Ansible role that deploys microservices, of whom I have a list of.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |