# Can't seem to change ansible\_ssh\_port value in-between plays

**URL:** <https://forum.ansible.com/t/cant-seem-to-change-ansible-ssh-port-value-in-between-plays/13901>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [November 13, 2013, 7:13pm UTC](https://forum.ansible.com/t/cant-seem-to-change-ansible-ssh-port-value-in-between-plays/13901 "2013-11-13T19:13:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Renaud\_Guerin](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@Renaud\_Guerin](https://forum.ansible.com/u/Renaud_Guerin)\
**Post date:** [November 13, 2013, 7:13pm UTC](https://forum.ansible.com/t/cant-seem-to-change-ansible-ssh-port-value-in-between-plays/13901/1 "2013-11-13T19:13:06Z")

</div>

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](http://xxxx.amazonaws.com)\> ESTABLISH CONNECTION FOR USER: ubuntu  
\<[xxxx.amazonaws.com](http://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 !
