community.general.cs_portforward (0.1.1) — module

Manages port forwarding rules on Apache CloudStack based clouds.

Authors: René Moser (@resmo)

stableinterface | supported by community

Install collection

Install with ansible-galaxy collection install community.general:==0.1.1


Add to requirements.yml

  collections:
    - name: community.general
      version: 0.1.1

Description

Create, update and remove port forwarding rules.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: 1.2.3.4:80 -> web01:8080
  cs_portforward:
    ip_address: 1.2.3.4
    vm: web01
    public_port: 80
    private_port: 8080
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: forward SSH and open firewall
  cs_portforward:
    ip_address: '{{ public_ip }}'
    vm: '{{ inventory_hostname }}'
    public_port: '{{ ansible_ssh_port }}'
    private_port: 22
    open_firewall: true
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: forward DNS traffic, but do not open firewall
  cs_portforward:
    ip_address: 1.2.3.4
    vm: '{{ inventory_hostname }}'
    public_port: 53
    private_port: 53
    protocol: udp
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: remove ssh port forwarding
  cs_portforward:
    ip_address: 1.2.3.4
    public_port: 22
    private_port: 22
    state: absent
  delegate_to: localhost

Inputs

    
vm:
    description:
    - Name of virtual machine which we make the port forwarding rule for.
    - Required if I(state=present).
    type: str

vpc:
    description:
    - Name of the VPC.
    type: str

tags:
    aliases:
    - tag
    description:
    - List of tags. Tags are a list of dictionaries having keys I(key) and I(value).
    - 'To delete all tags, set a empty list e.g. I(tags: []).'
    type: list

zone:
    description:
    - Name of the zone in which the virtual machine is in.
    - If not set, default zone is used.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - State of the port forwarding rule.
    type: str

domain:
    description:
    - Domain the I(vm) is related to.
    type: str

account:
    description:
    - Account the I(vm) is related to.
    type: str

api_key:
    description:
    - API key of the CloudStack API.
    - If not given, the C(CLOUDSTACK_KEY) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    type: str

api_url:
    description:
    - URL of the CloudStack API e.g. https://cloud.example.com/client/api.
    - If not given, the C(CLOUDSTACK_ENDPOINT) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    type: str

network:
    description:
    - Name of the network.
    type: str

project:
    description:
    - Name of the project the I(vm) is located in.
    type: str

protocol:
    choices:
    - tcp
    - udp
    default: tcp
    description:
    - Protocol of the port forwarding rule.
    type: str

api_region:
    default: cloudstack
    description:
    - Name of the ini section in the C(cloustack.ini) file.
    - If not given, the C(CLOUDSTACK_REGION) env variable is considered.
    type: str

api_secret:
    description:
    - Secret key of the CloudStack API.
    - If not set, the C(CLOUDSTACK_SECRET) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    type: str

ip_address:
    description:
    - Public IP address the rule is assigned to.
    required: true
    type: str

poll_async:
    default: true
    description:
    - Poll async jobs until job has finished.
    type: bool

api_timeout:
    description:
    - HTTP timeout in seconds.
    - If not given, the C(CLOUDSTACK_TIMEOUT) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    - Fallback value is 10 seconds if not specified.
    type: int

public_port:
    description:
    - Start public port for this rule.
    required: true
    type: int

vm_guest_ip:
    description:
    - VM guest NIC secondary IP address for the port forwarding rule.
    type: str

private_port:
    description:
    - Start private port for this rule.
    required: true
    type: int

open_firewall:
    default: false
    description:
    - Whether the firewall rule for public port should be created, while creating the
      new rule.
    - Use M(cs_firewall) for managing firewall rules.
    type: bool

api_http_method:
    choices:
    - get
    - post
    description:
    - HTTP method used to query the API endpoint.
    - If not given, the C(CLOUDSTACK_METHOD) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    - Fallback value is C(get) if not specified.
    type: str

public_end_port:
    description:
    - End public port for this rule.
    - If not specified equal I(public_port).
    type: int

private_end_port:
    description:
    - End private port for this rule.
    - If not specified equal I(private_port).
    type: int

Outputs

id:
  description: UUID of the public IP address.
  returned: success
  sample: a6f7a5fc-43f8-11e5-a151-feff819cdc9f
  type: str
ip_address:
  description: Public IP address.
  returned: success
  sample: 1.2.3.4
  type: str
network:
  description: Name of the network.
  returned: success
  sample: dmz
  type: str
private_end_port:
  description: End port on the virtual machine's IP address.
  returned: success
  sample: 80
  type: int
private_port:
  description: Start port on the virtual machine's IP address.
  returned: success
  sample: 80
  type: int
protocol:
  description: Protocol.
  returned: success
  sample: tcp
  type: str
public_end_port:
  description: End port on the public IP address.
  returned: success
  sample: 80
  type: int
public_port:
  description: Start port on the public IP address.
  returned: success
  sample: 80
  type: int
tags:
  description: Tags related to the port forwarding.
  returned: success
  sample: []
  type: list
vm_display_name:
  description: Display name of the virtual machine.
  returned: success
  sample: web-01
  type: str
vm_guest_ip:
  description: IP of the virtual machine.
  returned: success
  sample: 10.101.65.152
  type: str
vm_name:
  description: Name of the virtual machine.
  returned: success
  sample: web-01
  type: str
vpc:
  description: Name of the VPC.
  returned: success
  sample: my_vpc
  type: str