Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying custom SSH port does not work #411

Open
walterdolce opened this issue Oct 15, 2019 · 1 comment
Open

Specifying custom SSH port does not work #411

walterdolce opened this issue Oct 15, 2019 · 1 comment

Comments

@walterdolce
Copy link

Probably relates to test-kitchen/test-kitchen#1159

I have the following scenario at play:

  • I have a VM which should have port 22 disabled but still have the SSH daemon listening on another arbitrary port, say 444
  • I can kitchen create the VM just fine. The kitchen-vagrant driver will use port forwarding 22 => 2222 as per default behaviour.
  • I then provision the VM. I can therefore kitchen converge the VM just fine over port 22 => 2222. This is where Ansible (or any other provisioner) would configure the SSH daemon inside the VM to not listen on port 22 anymore but listen on port 444 as mentioned above.
  • From here on, I can no longer SSH into the VM because obviously the 22 => 2222 default port-forwarding would no longer work. The SSH daemon inside the VM is listening on port 444 after its first provisioning.

How can I tell kitchen-vagrant to connect to the VM via port 444?

So far I have tried using the following, either in combination or in isolation, but none of them have worked:

# .kitchen.yml
driver:
  name: vagrant
  communicator: ssh  # whether or not I specify this, it makes no difference
  network:
    - ["forwarded_port", {guest: 444, host: 444, auto_correct: true}]

# Does not really matter how I define the below, it never works
platforms:
  - name: ubuntu-16.04
    transport:
      name: ssh
      port: 444
    driver:
      port: 444
    driver_config:
      port: 444

I would expect that if I modify the port settings of the driver, instead of seeing the following:

       ==> default: Forwarding ports...
           default: 444 (guest) => 444 (host) (adapter 1)
           default: 22 (guest) => 2222 (host) (adapter 1)
       ==> default: Running 'pre-boot' VM customizations...
       ==> default: Booting VM...
       ==> default: Waiting for machine to boot. This may take a few minutes...
           default: SSH address: 127.0.0.1:2222

I would see the following:

       ==> default: Waiting for machine to boot. This may take a few minutes...
           default: SSH address: 127.0.0.1:444

But that doesn't happen. It's probably also worth mentioning that the automatically generated "test-kitchen state" (I think it's called..) remains the same all the time:

# .kitchen/default-ubuntu-1604.yml
---
hostname: 127.0.0.1
port: '2222'
username: vagrant
ssh_key: "/path/to/project/.kitchen/kitchen-vagrant/default-ubuntu-1604/.vagrant/machines/default/virtualbox/private_key"
last_action: create
last_error: 

But I would expect to see port: 444. That doesn't happen either.

What am I missing?

Thanks!

@walterdolce
Copy link
Author

In order to overcome the above, I had to do the following, which less than ideal 😅 :

# kitchen.yml
---
lifecycle:
  pre_converge:
    - local: |
        sed -i '' "s/port: '.*'/port: '4443'/g" .kitchen/${KITCHEN_INSTANCE_NAME}.yml

driver:
  name: vagrant
  network:
    - ["forwarded_port", {guest: 444, host: 444, auto_correct: true}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants