Skip to content

Ansible Role Development

Here is a suggested workflow for working on Ansible roles

The idea is to regard roles as something that are reusable and can be worked on in their own right.

To do this we have checked out repos in our roles folder which correspond to Github repos and Ansible Galaxy packages

Checking the Git Status of roles:

try this one liner to check the status of your roles:

for d in edmondscommerce.*; do cd $d;printf "\n\n--------------------\n\n"; pwd;  git status; cd ../; done

Installing Roles

Suggest you use this playbook:

This will checkout the remote repos. It will keep them as git modules so you can then work on them as you would expect

- hosts: localhost

  tasks:
    - name: Remove any none git folders from the roles directory. We assume that if it is a git repo, its being developed on locally and should not be removed.
      shell: find roles -mindepth 1 -maxdepth 1 -type d '!' -exec test -e '{}/.git' ';' -print | xargs rm -rf

    - name: Install Galaxy Roles in the requirements.yml file
      local_action:
        command ansible-galaxy install \
          --force \
          --keep-scm-meta \
          --role-file={{ playbook_dir }}/../requirements.yml \
          --roles-path={{ playbook_dir }}/../roles

    - name: Make sure the roles directory is being git ignored
      shell: printf "*\n!.gitignore" > {{ playbook_dir }}/../roles/.gitignore

Working on Roles in the Roles Folder

Once you do the above, you should have checked out repos for all our roles

Now you can work on them in the context of your ansible project, but commit and push updates to the roles as you go

Getting Git Status on our Roles

When you have your checked out roles and you are working on them, you probably want ot check git status

Try this one liner:

 for d in edmondscommerce.*; do cd $d;printf "\n\n--------------------\n\n"; pwd;  git status; cd ../; done

Bulk Updating All the Roles

A bit lazy, but sometimes you need to save time

Try this one liner to commit and push all of our roles:

 for d in edmondscommerce.*; do cd $d;printf "\n\n--------------------\n\n"; pwd;  git status; cd ../; done