# Req. help w/ problem: cs\_portforward causing error.

**URL:** <https://forum.ansible.com/t/req-help-w-problem-cs-portforward-causing-error/24650>\
**Category:** Ansible Project\
**Created:** [June 5, 2017, 6:16pm UTC](https://forum.ansible.com/t/req-help-w-problem-cs-portforward-causing-error/24650 "2017-06-05T18:16:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Rose](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@David\_Rose](https://forum.ansible.com/u/David_Rose)\
**Post date:** [June 5, 2017, 6:16pm UTC](https://forum.ansible.com/t/req-help-w-problem-cs-portforward-causing-error/24650/1 "2017-06-05T18:16:09Z")

</div>

Hello all  
I am trying to get started with CloudStack provisioning, and am running into a problem. I have a task defined which should do 3 actions:

- Instantiate 2 VMs (linsrv04 & linsrv05)
- Open ports in the firewall
- Create a portforward from the opened public port to the VM.  
Steps 1 & 2 finish successfully: However, task 3 fails.

> $ ansible-playbook -i inventory.yml cloudstack\_provision.yml  
> PLAY [Provision, or ensure as provisioned, VM instances in the BT Cloud.] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [linsrv05]  
> ok: [linsrv04]
> 
> TASK [cloudstack\_provision : Build VM or ensure it is already established.] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [linsrv04 → localhost]  
> ok: [linsrv05 → localhost]
> 
> TASK [cloudstack\_provision : Ensure ports opened on Public IP address] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [linsrv04 → localhost]  
> ok: [linsrv05 → localhost]
> 
> TASK [cloudstack\_provision : Ensure firewall port(s) opened and forward ports from public port to private port.] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [linsrv05 → localhost]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “Virtual machine ‘linsrv05’ not found”}  
> fatal: [linsrv04 → localhost]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “Virtual machine ‘linsrv05’ not found”}  
> to retry, use: --limit @/home/drose/ansible/cloudstack\_provision.retry
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> linsrv04 : ok=3 changed=0 unreachable=0 failed=1  
> linsrv05 : ok=3 changed=0 unreachable=0 failed=1

re-running in -vvvv mode, I see the following for the failure:

> fatal: [linsrv04 → localhost]: FAILED! =\> {  
> “changed”: false,  
> “failed”: true,  
> “invocation”: {  
> “module\_args”: {  
> “account”: null,  
> “api\_http\_method”: “get”,  
> “api\_key”: null,  
> “api\_region”: “Dave\_CMS4”,  
> “api\_secret”: null,  
> “api\_timeout”: 10,  
> “api\_url”: null,  
> “domain”: null,  
> “ip\_address”: “75.124.77.62”,  
> “network”: null,  
> “open\_firewall”: false,  
> “poll\_async”: true,  
> “private\_end\_port”: null,  
> “private\_port”: 22,  
> “project”: null,  
> “protocol”: “tcp”,  
> “public\_end\_port”: null,  
> “public\_port”: 2222,  
> “state”: “present”,  
> “vm”: “linsrv05”,  
> “vm\_guest\_ip”: null,  
> “vpc”: null,  
> “zone”: null  
> }  
> },  
> “msg”: “Virtual machine ‘linsrv05’ not found”  
> }  
> fatal: [linsrv05 → localhost]: FAILED! =\> {  
> “changed”: false,  
> “failed”: true,  
> “invocation”: {  
> “module\_args”: {  
> “account”: null,  
> “api\_http\_method”: “get”,  
> “api\_key”: null,  
> “api\_region”: “Dave\_CMS4”,  
> “api\_secret”: null,  
> “api\_timeout”: 10,  
> “api\_url”: null,  
> “domain”: null,  
> “ip\_address”: “75.124.77.62”,  
> “network”: null,  
> “open\_firewall”: false,  
> “poll\_async”: true,  
> “private\_end\_port”: null,  
> “private\_port”: 22,  
> “project”: null,  
> “protocol”: “tcp”,  
> “public\_end\_port”: null,  
> “public\_port”: 2322,  
> “state”: “present”,  
> “vm”: “linsrv05”,  
> “vm\_guest\_ip”: null,  
> “vpc”: null,  
> “zone”: null  
> }  
> },  
> “msg”: “Virtual machine ‘linsrv05’ not found”  
> }  
> to retry, use: --limit @/home/drose/ansible/cloudstack\_provision.retry

I don’t understand why I have the specific error the VMs can’t be found. Here is a slightly edited list of VMs running in the cloud account …

> Name State Offering Zone Account IP’s  
> linsrv04 Running 1vCPU-2660MHz-4GB-RAM US-NEW-NUT-G-V-A-R-S-001 **_Cloud\_Compute\_USD_**.rose@\*\*.com 10.1.0.22  
> linsrv05 Running 1vCPU-2660MHz-4GB-RAM US-NEW-NUT-G-V-A-R-S-001 **_Cloud\_Compute\_USD_**.rose@\*\*.com 10.1.0.23  
> Total number of virtual machines: 11

Here is the task/main.yml file:

> * * *
> 
> - name: Build VM or ensure it is already established.  
> local\_action:  
> module : cs\_instance  
> api\_region : “{{ api\_region }}” ## This is in the ./cloudstack.ini file.  
> name : “{{ inventory\_hostname\_short }}”  
> service\_offering : “{{ cs\_1cpu4gb }}”  
> template : “{{ iso\_template }}”  
> ip\_to\_networks :
> - network : “{{ network }}”  
> ip : “{{ ansible\_host }}”  
> zone : “{{ cs\_zone }}”  
> state : started

> - name: Ensure ports opened on Public IP address
> 
> local\_action:  
> module : cs\_firewall  
> api\_region : “{{ api\_region }}” ## This is in the ./cloudstack.ini file.  
> cidr : 0.0.0.0/0  
> ip\_address : “{{ public\_ip }}” ## This is the IP Address of the internal VM.  
> port : “{{ ansible\_ssh\_public\_port }}” ## Open the public port.
> 
> # when : public\_ip is defined

> - name: Ensure firewall port(s) opened and forward ports from public port to private port.
> 
> local\_action:  
> module : cs\_portforward  
> api\_region : “{{ api\_region }}” ## This is in the ./cloudstack.ini file.  
> ip\_address : “{{ public\_ip }}” ## This is the Public IP Address  
> vm : “{{ inventory\_hostname }}”  
> public\_port : “{{ ansible\_ssh\_public\_port }}”  
> private\_port : “{{ ansible\_ssh\_port }}”  
> protocol : tcp
> 
> # open\_firewall : true

Appreciate any help or direction anyone can provide …  
-dave

---

<div class="post-metadata">

**Author:** ![David\_Rose](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@David\_Rose](https://forum.ansible.com/u/David_Rose)\
**Post date:** [June 5, 2017, 6:25pm UTC](https://forum.ansible.com/t/req-help-w-problem-cs-portforward-causing-error/24650/2 "2017-06-05T18:25:45Z")

</div>

And here is how it is called …

> * * *
> 
> - name: Provision, or ensure as provisioned, VM instances in the \*\* Cloud.  
> hosts: “{{ cs\_hosts }}”  
> connection: local  
> become: no  
> gather\_facts: yes  
> roles:
> - cloudstack\_provision

Thanks!  
-dave
