nttmcp / nttmcp.mcp / 1.0.9 / module / ansible_gw List, Create and Destory an Ansible Bastion Host | "added in version" 2.10.0 of nttmcp.mcp" Authors: Ken Sinfield (@kensinfield) preview | supported by NTT Ltd.nttmcp.mcp.ansible_gw (1.0.9) — module
Install with ansible-galaxy collection install nttmcp.mcp:==1.0.9
collections: - name: nttmcp.mcp version: 1.0.9
List, Create and Destory an Ansible Bastion Host
# Creating an Ansible gateway - hosts: localhost gather_facts: no connection: local collections: - nttmcp.mcp tasks: - name: Deploy an Ansible Gateway ansible_gw: region: na datacenter: NA12 network_domain: myCND vlan: myVLAN image: "CentOS 7 64-bit 2 CPU" src_ip: x.x.x.x state: present - name: Delete an Ansible Gateway ansible_gw: region: na datacenter: NA12 network_domain: myCND vlan: myVLAN name: ansible_gw state: absent
# Full use case (Playbook) - hosts: localhost gather_facts: no connection: local collections: - nttmcp.mcp vars: # Modify these if you really want region: na datacenter: NA12 image: "CentOS 7 64-bit 2 CPU" cnd: myCND2 cnd_description: "My CND2" vlan: myVLAN2 my_host: "12.167.142.34" # Do NOT modify these ansible_gateway: "ansible_gateway" tasks: - name: Generate Host Password set_fact: host_password: "{{lookup('password', './host_passwd_file chars=ascii_letters,.:{}()-_+=')}}" tags: - testing - create - name: Show host password debug: var: host_password tags: - create - local_action: stat path=public_ipv4 register: public_ipv4_state become: no tags: - testing - create - delete - name: Create the CND network: region: "{{region}}" datacenter: "{{datacenter}}" name: "{{cnd}}" description: "{{cnd_description}}" state: present tags: - testing - create register: cnd_return - name: Create the VLAN vlan: region: "{{region}}" datacenter: "{{datacenter}}" network_domain: "{{cnd}}" name: "{{vlan}}" ipv4_network_address: "172.16.0.0" ipv4_prefix_size: 24 state: present tags: - testing - create register: vlan_return - name: Deploy an Ansible Gateway ansible_gw: region: "{{region}}" datacenter: "{{datacenter}}" name: "ANSIBLE_TEST" network_domain: "{{cnd}}" vlan: "{{vlan}}" image: "{{image}}" src_ip: "{{my_host}}" state: present tags: - testing - create register: server - name: debug debug: var: server tags: - create - set_fact: ansible_pw: "{{server.data.password | default(host_password)}}" ansible_gw: "{{server.data.public_ipv4}}" tags: - testing - create - set_fact: ansible_pw: "{{host_password}}" when: server.data.password == None tags: - testing - create - debug: var: ansible_pw tags: - testing - create - name: Add_Host add_host: name: "{{ansible_gw}}" tags: - testing - create - debug: var: ansible_gw tags: - testing - create - name: Remove an Ansible Gateway ansible_gw: region: "{{region}}" datacenter: "{{datacenter}}" name: "ANSIBLE_TEST" network_domain: "{{cnd}}" vlan: "{{vlan}}" state: absent register: remove_server tags: - testing - delete - name: Debug Removal of the Ansible gateway debug: var: remove_server tags: - testing - delete - name: Remove the VLAN vlan: region: "{{region}}" datacenter: "{{datacenter}}" network_domain: "{{cnd}}" name: "{{vlan}}" state: absent tags: - testing - delete - name: Remove the CND network: region: "{{region}}" datacenter: "{{datacenter}}" name: "{{cnd}}" state: absent tags: - testing - delete
- hosts: "{{hostvars.localhost.ansible_gw}}" gather_facts: no environment: host_key_checking: False vars: ansible_user: root ansible_gw: "{{hostvars['localhost']['ansible_gw']}}" ansible_pw: "{{hostvars['localhost']['ansible_pw']}}" ansible_ssh_common_args: '-o StrictHostKeyChecking=no' ansible_ssh_pass: "{{ ansible_pw }}" tasks: - debug: var: ansible_pw tags: - testing - create - name: Get Hostname shell: hostname register: hostname tags: - testing - create - debug: var: hostname tags: - testing - create
auth: description: - Optional dictionary containing the authentication and API information for Cloud Control required: false suboptions: api: description: - The Cloud Control API endpoint e.g. api-na.mcp-services.net required: false type: str api_version: description: - The Cloud Control API version e.g. 2.11 required: false type: str password: description: - The Cloud Control API user password required: false type: str username: description: - The Cloud Control API username required: false type: str type: dict ipv4: description: - The IPv4 address of the host - If one is not provided one will be automatically allocated required: false type: str name: default: ansible_gw description: - The name of the Bastion Host required: false type: str vlan: description: - The name of the VLAN to create the Bastion Host in required: true type: str wait: default: true description: - Wait for the server to complete deployment required: false type: bool image: description: - The name of the Image to use whend creating a new server - Must be a Linux based image - Use infrastructure -> state=get_image to get a list - of that available images required: false type: str state: choices: - present - absent default: present description: - The action to be performed required: false type: str region: default: na description: - The geographical region required: false type: str src_ip: default: ANY description: - The IPv4 source network/host address to restrict SSH access to the Bastion Host public IPv4 address required: false type: str password: description: - The root password for the host required: false type: str wait_time: default: 1200 description: - The maximum time the module will wait for the server to complete deployment in seconds required: false type: int datacenter: description: - The datacenter name required: true type: str src_prefix: description: - The IPv4 subnet mask to apply to the src_ip address required: false type: str network_domain: description: - The name of a Cloud Network Domain required: true type: str wait_poll_interval: default: 30 description: - How often the module will poll the Cloud Control API to check the status of the Bastion Host deployment in seconds required: false type: int
data: contains: id: description: The UUID of the server sample: b2fbd7e6-ddbb-4eb6-a2dd-ad048bc5b9ae type: str ipv6: description: The IPv6 address of the Bastion Host sample: 1111:1111:1111:1111:0:0:0:1 type: str password: description: The password for the server if generated by the module sample: my_password type: str private_ipv4: description: The private IPv4 address of the Bastion Host sample: 10.0.0.10 type: str public_ipv4: description: The public IPv4 address assigned to the Bastion Host sample: x.x.x.x type: str description: Object with the Bastion Host details returned: when state == present type: complex