Attempting to save a variable's value for backup before modifying it doesn't work.
I have the following inventory file (note the custom ansible_port and user):
all:
hosts:
test:
ansible_port: 11111
ansible_user: user_foo
ansible_host: 192.168.56.101
And I have the following playbook:
- name: Test
hosts: test
vars:
backup_ansible_port: "{{ ansible_port }}"
backup_ansible_user: "{{ ansible_user }}"
ansible_port: "{{ tmp_port }}"
ansible_user: root
tasks:
- name: foo
debug:
msg:
- "{{ backup_ansible_port }}"
- "{{ backup_ansible_user }}"
- "{{ ansible_port }}"
- "{{ ansible_user }}"
Running the following command:
ansible-playbook bootstrap_ssh.yml --ask-pass -e 'target=test tmp_port=22'
The output is the following:
...
TASK [foo] *********************************
ok: [test] => {
"msg": [
"22",
"root",
"22",
"root"
]
}
...
Expected output:
...
TASK [foo] *********************************
ok: [test] => {
"msg": [
"11111",
"user_foo",
"22",
"root"
]
}
...
Why is this not the case?