Hello guys, In the DevOps world, the configuration management plays vital role when the auto deployment comes into picture. Chef, puppet and Ansible are the pioneers in this era.
My expertise are in DevOps and Cloud world. Devops is amazing and i feel proud myself to be a part of that. This blog is really for those enthusiast who are passionate for DevOps and want to learn/contribute to that.
I will detail out how the CI and CD can be integrated with simple Sinatra based Jenkins plugin which fetches the list of nodes based on the filter criteria provided in the job configuration.
As a part of CI, the build artifacts will be generated along with cookbook artifacts for the particular environment and this plugin will be used to deploy the build artifact on selected nodes.
This will just solve the issue of executing chef client on different nodes based on some filter
- Plugin architecture :
- Extension point : Builder
- adds as a build task which performs the few operations and execute the chef-client on selected nodes based on the job configuration.
- Call to Sinatra chef gem
- Sinatra gem is running on some machine which will continuously ping the chef server and update the XML output.
- XML parser to get the list of nodes
- once we have the list of nodes. The chef-client can run sequentially as well as in parallel. This truly dependent on job configuration.
- Here is the UI option in the Jenkins job configuration:
- URL: the url which contains all the required info to fetch the nodes and cookbook filter
- filter: cookbookname::filter
- Validate button: Validate the syntax and report any issue to the user if the syntax is not correct
- fetch nodes button: fetch the list of nodes based on the fiilter given above
- save the configuration
- Build flow:
- Based on the job configuration , the chef client will be executed.
- the java ssh client is being used to execute the command and get the output.
- chef_handler resource will be called to report out any issues and exception to validate if the chef client runs properly or not
- build will be marked failed if any of the chef client fails on any of the node. this is required to have to catch the exception and make decision based on that.
- Chef server:
- Enterprise as well as open source chef server should work here. The user which is configured to do ssh in the sinatra app should have passwordless authentication
- The user should be able to ssh to all nodes fetched by that filter
Please refer below the Jenkins configuration page snippet:
Now, when we press the build button, the perform descriptor of the plugin gets executed and java ssh client runs to run chef-client on different nodes.
Additionally, Multiple chef servers can be added in the global configuration of Jenkins to have a full coverage of chef infrastructure.
Refer below the snippet:
Have a look and let me know how you think about it. Thanks
Reference: I love reading books: Continuous Delivery By Jez Humble: