Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible: task naming style

Tags:

ansible

Are there conventions regarding task names, e.g. all examples seem to have an leading lower case letter, but is that a official recommendation ?

All examples I see on ansible website e.g. at https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html use this style ...

  tasks:
  - name: ensure apache is at the latest version
    yum:
      name: httpd
      state: latest

as opposed to Ensure apache is at the latest version.

However when I use gather_facts: true in my playbook I see the built-in ansible generated ...

TASK [Gathering Facts] 

which seems inconsistent?

I know this may seem trivial point, but if we are writing lots of plays I'd like to ensure we adhere to conventions.

like image 225
k1eran Avatar asked Nov 07 '22 13:11

k1eran


1 Answers

For the moment you are in a good spot if you name all your tasks, regardless how you do it. Ansible-lint can clearly help you achieve that.

Another recommendations I have:

  • to avoid reusing the same task name anywhere inside the the same repository
  • avoid using variable expansions in tasks because it may make harder to search for broken task later, in some cases expansion does not even work as you would expect (aka loops).

BTW, if you want to propose more restrictive checks for ansible-lint, I will be happy to review your change.

like image 186
sorin Avatar answered Nov 11 '22 12:11

sorin