Ansible playbooks, roles with default / override values

January 9, 2024

Playbook:

- name: "Install pyenv globally"
  hosts: "{{ target_host | default('dev') }}"
  become: true
  gather_facts: false
 
  tasks:
    - name: "Install and configure pyenv"
      ansible.builtin.include_role:
        name: install_pyenv
      vars:
        pyenv_python_versions: ["3.11.7", "3.9.9", "3.8.12"]
  • calls a role, which defines a default run configuration
    • specifies defaults, tasks, templates
  • you can pass values to the vars parameter to override the defaults in the role