2

I want to be able to set which port to use for ssh forwarding when running up kitchen converge.

I added the forwarded_port lines to .kitchen.yml:

---                                                                                                                                                        
driver:
  name: vagrant
  network:·
    - ["forwarded_port", {guest: 22, host: 2223}]

But kitchen still uses the default port for ssh:

~/D/octopress git:source ❯❯❯ netstat -n -p tcp | grep 22                                                                                  
....
tcp4       0      0  127.0.0.1.2200         127.0.0.1.59456        ESTABLISHED
tcp4       0      0  127.0.0.1.59456        127.0.0.1.2200         ESTABLISHED

Apparently a mapping is created but kitchen is not using it. enter image description here

I have checked chef website and this page does not provide more in-depth info

How can I override the default ssh port?

Anthony Kong
  • 4,868
  • 11
  • 48
  • 80

1 Answers1

1

You didn't give the name of your kitchen instance name, so I will make up a name to proceed with an example. If, in kitchen, in a cookbook, you created a server called 'default-centos-75', you would edit the following file in the home directory of that cookbook:

vi .kitchen/default-centos-75.yml

You would then find the line that begins port: and change the port number to your desired port. For instance, change port: 2222 to port: 2223

Andrew
  • 209
  • 2
  • 3
  • This does not work, as kitchen changes the values back to defaults on the next run. – Chaim Eliyah Dec 17 '18 at 19:43
  • @ChaimEliyah - You are right it does not survive a kitchen destroy or re-run of kitchen create. But, it works once you run kitchen create and modify the file as I describe! You CAN re-run kitchen converge over-and-over without losing the settings. Just avoid re-running kitchen create. – Andrew Feb 07 '19 at 15:40
  • Ah okay. Yes that seems like a good troubleshooting step between runs. I have now forgotten what problem I made the comment for. XD – Chaim Eliyah Feb 07 '19 at 23:04
  • This situation occurs when you: 1) create a VM using kitchen; 2) stop the VM without destroying it (e.g. shutdown -h); 3) re-run kitchen create. If you then want to start the first VM and connect to it using kitchen login command, you have to: 5) change the port mapping for the first VM as you show in the UI, and finally 6) change .kitchen/default-centos-75.yml (or whatever node-name.yml you created with kitchen create) as I show above, matching the updated port mappings you input into the UI – Andrew Feb 13 '19 at 21:42