Workspace screenshots

Ansible-Terraform Workspace. Part 2

development environment with Ansible, Terraform, and lots of other applications in one docker image.

4 min readSep 19, 2021

--

Ansible-Terraform Workspace Part 1

This is Part 2 of the publications about Ansible-Terraform workspace — a docker image, that contains a toolkit to work with Ansible and Terraform, including several browser-based applications to schedule jobs, visualize infrastructures, terraform plan visualization, dashboard of Ansible playbooks and more.

Part 2 describes Ansible toolkit of Ansible-Terraform workspace, with examples and code snippets.

The workspace includes example ansible-playbook — a simple play that installs packages in localhosts

cd /home/examples/ansible-local && ansible-playbook install-packages.yml

Ansible Ara

ARA Records Ansible and makes it easier to understand and troubleshoot. Ansible Ara is fully configured in the Ansible-Terraform workspace — it captures any execution (manual or scheduled) of any ansible playbook.

Ara server is up and running in the workspace, and available on the internal port 8029. If you mapped standard ports to your Ansible-Terraform workspcae, then Ansible Ara WEB UI is on localhost:8029

Ansible Ara demo

Ansible report

Ansible-report is a small utility that generates several reports from your ansible project — visualizes inventory, represents all plays in a format of graphs, generates interactive static website with information about hosts etc.

cd /home/examples/ansible-local && ansible-report

Ansible-report is a shell script that simply executes several ansible tools in one shot:

  • ansible-lint
  • ansible-cmdb
  • ansible-inventory-grapher
  • ansible-playbook-grapher (for all ansible plays in the folder)

You can also use any of the ansible toos separately.

Ansible report

Ansible Lint

Ansible Lint is a command-line tool for linting playbooks, roles and collections aimed towards any Ansible users. Cd to the folder with your Ansible project and execute

ansible-lint --nocolor > /home/static-server/ansible-lint.txt

Ansible-cmdb

Ansible-cmdb takes the output of Ansible’s fact gathering and converts it into a static HTML overview page (and other things) containing system configuration information. Cd to the folder with your Ansible project and execute

ansible -m setup --tree out/ all
ansible-cmdb out/ > overview.html

Ansible inventory grapher

Ansible-inventory-grapher creates a dot file suitable for use by graphviz. Cd to the folder with your Ansible project and execute

ansible-inventory-grapher all | dot -Tpng > /home/static-server/my.png

Ansible Playbook Grapher

Command line tool to create a graph representing your Ansible playbook plays, tasks and roles. The aim of this project is to have an overview of your playbook. Cd to the folder with your Ansible project and execute

ansible-playbook-grapher --include-role-tasks example.yml -o /home/static-server/example

Ansible Doctor

Ansible-doctor is a simple annotation like documentation generator based on Jinja2 templates. hile ansible-doctor comes with a default template called readme, it is also possible to write your own templates.

The first step is to identify if the given folder is an Ansible role. This check is very simple, if the folder contains a sub-directory called tasks is MUST be an Ansible role! :)

After the successful check, ansible-doctor will try to read some static files into a dictionary:

  • defaults/main.yml
  • meta/main.yml

Cd to the folder with your Ansible project and execute

ansible-doctor -o /home/static-server/ roles/example_production

Schedule Ansible playbook executions

Ansible-Terraform workspace has 2 tools (Cronicle and ARA) that make it simple and convenient to use Ansible for periodic tasks and jobs. For example, maintenance jobs for your cloud infrastructure. This is especially handy if you run this workspace on a remote server.

  • [Cronicle] — allows to schedule tasks and jobs, and lets you observe executions using a nice UI
  • [Ansible Ara] — tracks all executions of ansible playbooks (manual or scheduled), and has nice UI that provides informationn about every step of every playbook execution

You can try scheduling an example ansible playbook with Cronicle

Schedule Ansible playbooks with Cronicle

NOTE: Scheduling Ansible playbooks is especially useful if you launch Workspace on a remote server rather than on your local laptop.

Ansible-Terraform Workspace Part 3

--

--