Ansible Pattern: Meta Role

Published On: 2017-06-17, Reading Time: 1 minute

This pattern is used to provide a quick way to include multiple roles at once. For example if you have a group of things that every server needs, you could use a meta role to include those things with one line.

So lets say you have three roles for every machine named users, ssh and logs_to_syslog_server. You can include them all by making a role named common. In that common role you make a file named meta/main.yml and put the following contents in it.

  - role: users
  - role: ssh
  - role: logs_to_syslog_server

The on every host you simply add the common role.

  - role: common
    tags: [common]

and suddenly you get all the common roles. You can also run with -t common to run all the common rules. This is handy if something global to your infrastructure is updated and you would like all hosts to receive the update.

comments powered by Disqus