Hi,
I’ve got a playbook that looks a bit like this :
- hosts: not_boostrapped # this group comes from an earlier group_by
accelerate: false
sudo: true
gather_facts: false
vars_files: - bootstrap_vars.yml’ # this contains “ansible_ssh_port: 22”
roles: - { role: common, sudo: true, bootstrap_only: yes } # this role has “ansible_ssh_port: 2000” in defaults/main.yml, but is overriden correctly to 22 in the vars_files above, for this play only.
At this point sshd has been restarted with a new config and is listening on port 2000
Moving on to the second play…
- hosts: webservers
sudo: true
accelerate: true
gather_facts: false
roles:
- common # this still has “ansible_ssh_port: 2000” in defaults/main.yml (also tried with vars/main.yml, same) and this time nothing should override it, right ?
So, I’m expecting the second play to use ssh port 2000, after the first play has moved sshd there.
What happens is :
- When the first play is skipped (i.e. because the host was already bootstrapped) and only the second play runs, this works fine.
- However, when the 2 plays run in sequence, the second play still tries to connect to port 22 (and fails, because sshd has moved) even though it shouldn’t :
"Falling back to ssh to startup accelerated mode
attempting to start up the accelerate daemon…
<xxxx.amazonaws.com> ESTABLISH CONNECTION FOR USER: ubuntu
<xxxx.amazonaws.com> EXEC [‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/renaudg/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’
…"
Shouldn’t variables defined in the first play’s vars_files have scope only in that play ?
Here, it seems like either their value carries over to the second play, or ansible-playbook doesn’t register a change of value for ansible_ssh_port in between plays.
What’s happening ?
Thanks !