Release Pipeline for Ansible

Use Github Actions to automate the build, test, and release stages of the release pipeline for Ansible.

You will be using Github actions to automate the build, test, and release stages of the release pipeline. The idea is to have all the stages run after a commit or pull request is made to the master branch.

What makes up each stage?

Build

Ansible isn’t a compiled language, but it does have environmental requirements. Because the code will be running on a hosted agent provided by Github, Ansible won’t be installed. You will create an action that uses a Docker container to set up the build environment.

Test

You will start testing by using a linter. Ansible has a command-line utility called ansible-lint used to analyze your code and flag issues based on rules. After linting, other types of tests could be added to this stage. However, to start linting will be the only step in the test stage.

Release

The work that you did in the Building Reusable Configuration chapter has set you up for an easy release stage. All you need to do is run the site.yml playbook, and Ansible will take care of the rest. However, there are a few differences when running Ansible in the release pipeline. You will figure out how to populate environment variables that connect Ansible to your cloud provider. Also, you will learn how to pass the vault password into the ansible-playbook command.

Linting Ansible code

Ansible has a command-line tool for linting Ansible playbooks. Linter tools have the following functions:

  • Analyze source code
  • Flag programming errors, bugs, stylistic errors, and suspicious constructs

Let’s lint the configure_nginx_web_server.yml playbook. Click on the Run button and wait for the environment to set up.

Get hands-on with 1200+ tech skills courses.