Published on

An Approach to Naming Ansible Tasks and Commands

Authors

I worked with a colleague recently who has worked extensively with Ansible. One thing I learnt from him is a good convention for naming ansible tasks:

  • You name the task as normal but you number the tasks

This simple little convention makes it significantly easier to see at a glance what order the tasks run in without having to look inside main.yml. For example, my tasks folder looks as follows:

tasks/
		-> 1-base.yml
		-> 2-setup-git-repo.yml
		-> 3-setup-app.yml
		-> main.yml

Another approach I have used is numbering the actions in the task file so it is easy to identify when running a task what file it is from and what step. For example in my 3-setup-app.yml file I have named the commands as follows:

- name: 3.1 - Install app dependencies with pipenv
  command: '{{ pip_env_bin_path }} install'
  args:
    chdir: '{{ git_root }}'

- name: 3.2 - Ansible copy '.env' file from host to remote server
  copy:
    src: '{{ path_to_env_file }}'
    dest: '{{ git_root }}'

When this runs it is clear which task file's tasks are being run and easy to quickly go to the exact task command being run.