summaryrefslogtreecommitdiffstats
path: root/ansible_collections/awx/awx/plugins/modules/instance.py
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/awx/awx/plugins/modules/instance.py')
-rw-r--r--ansible_collections/awx/awx/plugins/modules/instance.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/ansible_collections/awx/awx/plugins/modules/instance.py b/ansible_collections/awx/awx/plugins/modules/instance.py
index 049dd976d..af7360687 100644
--- a/ansible_collections/awx/awx/plugins/modules/instance.py
+++ b/ansible_collections/awx/awx/plugins/modules/instance.py
@@ -47,6 +47,7 @@ options:
- Role that this node plays in the mesh.
choices:
- execution
+ - hop
required: False
type: str
node_state:
@@ -62,6 +63,20 @@ options:
- Port that Receptor will listen for incoming connections on.
required: False
type: int
+ peers:
+ description:
+ - List of peers to connect outbound to. Only configurable for hop and execution nodes.
+ - To remove all current peers, set value to an empty list, [].
+ - Each item is an ID or address of a receptor address.
+ - If item is address, it must be unique across all receptor addresses.
+ required: False
+ type: list
+ elements: str
+ peers_from_control_nodes:
+ description:
+ - If enabled, control plane nodes will automatically peer to this node.
+ required: False
+ type: bool
extends_documentation_fragment: awx.awx.auth
'''
@@ -70,12 +85,24 @@ EXAMPLES = '''
awx.awx.instance:
hostname: my-instance.prod.example.com
capacity_adjustment: 0.4
- listener_port: 31337
- name: Deprovision the instance
awx.awx.instance:
hostname: my-instance.prod.example.com
node_state: deprovisioning
+
+- name: Create execution node
+ awx.awx.instance:
+ hostname: execution.example.com
+ node_type: execution
+ peers:
+ - 12
+ - route.to.hop.example.com
+
+- name: Remove peers
+ awx.awx.instance:
+ hostname: execution.example.com
+ peers:
'''
from ..module_utils.controller_api import ControllerAPIModule
@@ -88,9 +115,11 @@ def main():
capacity_adjustment=dict(type='float'),
enabled=dict(type='bool'),
managed_by_policy=dict(type='bool'),
- node_type=dict(type='str', choices=['execution']),
+ node_type=dict(type='str', choices=['execution', 'hop']),
node_state=dict(type='str', choices=['deprovisioning', 'installed']),
listener_port=dict(type='int'),
+ peers=dict(required=False, type='list', elements='str'),
+ peers_from_control_nodes=dict(required=False, type='bool'),
)
# Create a module for ourselves
@@ -104,10 +133,22 @@ def main():
node_type = module.params.get('node_type')
node_state = module.params.get('node_state')
listener_port = module.params.get('listener_port')
-
+ peers = module.params.get('peers')
+ peers_from_control_nodes = module.params.get('peers_from_control_nodes')
# Attempt to look up an existing item based on the provided data
existing_item = module.get_one('instances', name_or_id=hostname)
+ # peer item can be an id or address
+ # if address, get the id
+ peers_ids = []
+ if peers:
+ for p in peers:
+ if not p.isdigit():
+ p_id = module.get_one('receptor_addresses', allow_none=False, data={'address': p})
+ peers_ids.append(p_id['id'])
+ else:
+ peers_ids.append(p)
+
# Create the data that gets sent for create and update
new_fields = {'hostname': hostname}
if capacity_adjustment is not None:
@@ -122,6 +163,10 @@ def main():
new_fields['node_state'] = node_state
if listener_port is not None:
new_fields['listener_port'] = listener_port
+ if peers is not None:
+ new_fields['peers'] = peers_ids
+ if peers_from_control_nodes is not None:
+ new_fields['peers_from_control_nodes'] = peers_from_control_nodes
module.create_or_update_if_needed(
existing_item,