Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port forwarding not working with Test-Kitchen and Vagrant

I'm on Ubuntu Linux 14.04 and I'm trying to create a Centos VM using kitchen-vagrant. I want port forwarding so that I can forward apache tomcat on my local machine. It's not working though I've specified the port number and private network IPs like in their documentation. On my machine I get "site is unreachable".

---
driver:
  name: vagrant

provisioner:
  name: chef_zero

platforms:
  - name: centos-6.7
    network:
      - ["forwarded_port", {guest: 8080, host: 8080}]
      - ["private_network", {ip: "192.168.33.33"}]

suites:
  - name: default
    run_list:
      - recipe[env_rundeck_war::default]
    attributes:

When I log into the VM (kitchen login), I can access Tomcat on port 8080.

jose@jose-desktop $ kitchen login
...
[vagrant@default-centos-67 ~]$ curl -i localhost:8080
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Sat, 30 Jul 2016 18:12:23 GMT

I have tried moving the network settings under the driver section, but that didn't help either. It seems that's how they do it on the documentation.

like image 277
user3505901 Avatar asked Feb 07 '23 11:02

user3505901


1 Answers

Actually, network is a parameter of the (kitchen-vagrant) driver. Thus, the following configuration would be correct:

platforms:
  - name: centos-6.7
    driver_config:
      network:
        - ["forwarded_port", {guest: 8080, host: 8080}]
        - ["private_network", {ip: "192.168.33.33"}]

You can watch out the contents of the Vagrantfile in .kitchen/kitchen-vagrant/<suite>/ for the following line (to speed up your verification step):

c.vm.network(:forwarded_port, {:guest=>8080, :host=>8088})

Btw. you don't need a private_network if you only want to forward a port (you can omit that line).

like image 181
StephenKing Avatar answered Apr 09 '23 06:04

StephenKing