Var precedence

If you want to overrule variables in roles with variables defined in the playbook (or elsewhere) you might try something like this:

$ cat rolesvar.yml

  • hosts: localhost
    gather_facts: false
    vars:
    foo2: overruled_rom_role_invocation
    roles:
  • role: test
  • role: test
    foo: $foo2

$ ansible-playbook rolesvar.yml

PLAY [localhost] **************************************************************

TASK: [debug msg=default_from_role] *******************************************
ok: [localhost]

TASK: [debug msg=overruled_rom_role_invocation] *******************************
ok: [localhost]

PLAY RECAP ********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0

Serge