Linux Labs

Automation: Git and Ansible / Stage 7 of 8

Roles, variables and secrets

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 6 · summary · 3 min

Summary

  • A role is a roles/<name>/ directory: tasks in tasks/main.yml, handlers in handlers/main.yml, templates in templates/, default values in defaults/main.yml; a play calls it with the roles list and sets its own vars.
  • Group and machine variables live in group_vars/ and host_vars/ next to the inventory; of a role's defaults, group_vars, host_vars, a play's vars and -e, the later one in the list wins, and -e lasts one run.
  • ansible-vault encrypt encrypts a file with a secret, and a run decrypts it with the vault password from --ask-vault-pass or from vault_password_file; the password file lives outside the project.
  • The phone from the start of the lesson reached only shop because the playbooks were three copies of the tasks; with a role the edit is one line in defaults, and the database password is written once, in an encrypted file.
Ubuntu 24.04
Loading…