Assuming myvarsfile.yml
as in your question, given this playbook:
- hosts: localhost
gather_facts: false
tasks:
- include_vars: myvarsfile.yml
- debug:
msg: "given mypass={{ mypass }}, old password={{old_pass|default(vars[mypass])}}"
Running this command:
ansible-playbook playbook.yml -e mypass=newpass1
Produces:
PLAY [localhost] **********************************************************************************************************************************************************
TASK [include_vars] *******************************************************************************************************************************************************
ok: [localhost]
TASK [debug] **************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "given mypass=newpass1, old password=oldpass3"
}
PLAY RECAP ****************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
I believe that's the behavior you're looking for.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…