ansible_aap_api_client package
Subpackages
Submodules
ansible_aap_api_client.ansible_aap_api_client_cli module
CLI for ansible_aap_api_client
ansible_aap_api_client.base_connection module
A base connection class for the AAP API client.
ansible_aap_api_client.groups module
AAP Groups
- class ansible_aap_api_client.groups.Group(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
Bases:
_BaseConnection
Group class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
- add_host_to_group(group_id: int, host: InventoryHostRequestSchema) dict [source]
Add host to group
- Parameters:
group_id (int) – The group id
host (InventoryHostRequestSchema) – The host to add
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If host is not of type InventoryHostRequestSchema
- delete_group(group_id: int) int [source]
Delete group
- Parameters:
group_id (int) – The group id
- Return type:
Integer
- Returns:
Response Status Code
- Raises:
TypeError – If inventory_id is not of type int
- get_group(name: str) dict [source]
Get all instances of a group by name
- Parameters:
name (str) – The name of the group
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If name is not of type str
- get_group_id(name: str) int [source]
Get the id of a group if one exists
- Parameters:
name (str) – The name of the group
- Return type:
int
- Returns:
The id of the group
- Raises:
ValueError – If zero or more than one instance is found
TypeError – If name is not of type str
- groups_uri = '/groups/'
- update_group(group_id: int, group: InventoryGroupRequestSchema) dict [source]
Update group
- Parameters:
group_id (int) – The group id
group (InventoryGroupRequestSchema) – The group data
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If inventory is not a InventoryRequestSchema
TypeError – If inventory_id is not of type int
ansible_aap_api_client.hosts module
AAP Groups
- class ansible_aap_api_client.hosts.Host(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
Bases:
_BaseConnection
Host class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
- delete_host(host_id: int) int [source]
Delete a host
- Parameters:
host_id (int) – The id of the host
- Return type:
int
- Returns:
The id of the deleted host
- get_host(name: str) dict [source]
Get all instances of a host by name
- Parameters:
name (str) – The name of the host
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If name is not of type str
- get_host_id(name: str) int [source]
Get the id of a host if one exists
- Parameters:
name (str) – The name of the host
- Return type:
int
- Returns:
The id of the host
- Raises:
ValueError – If zero or more than one instance is found
TypeError – If name is not of type str
- hosts_uri = '/hosts/'
- update_host(host_id: int, host: InventoryHostRequestSchema) dict [source]
Update a host
- Parameters:
host_id (int) – The id of the host
host (InventoryHostRequestSchema) – The host object
- Return type:
dict
- Returns:
The updated host
ansible_aap_api_client.inventories module
AAP Inventories
- class ansible_aap_api_client.inventories.Inventory(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
Bases:
_BaseConnection
Inventory class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
- add_group_to_inventory(inventory_id: int, group: InventoryGroupRequestSchema) dict [source]
Add group to inventory
- Parameters:
inventory_id (int) – The inventory id
group (InventoryGroupRequestSchema) – The group to add
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If group is not an InventoryGroupRequestSchema
- add_host_to_inventory(inventory_id: int, host: InventoryHostRequestSchema) dict [source]
Add host to inventory
- Parameters:
inventory_id (int) – The inventory id
host (InventoryHostRequestSchema) – The host to add
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If host is not an InventoryHostRequestSchema
- create_inventory(inventory: InventoryRequestSchema) dict [source]
Create inventory
- Parameters:
inventory (InventoryRequestSchema) – The inventory to create
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If inventory is not a InventoryRequestSchema
- delete_inventory(inventory_id: int) int [source]
Delete inventory
- Parameters:
inventory_id (int) – The inventory id
- Return type:
Integer
- Returns:
Response Status Code
- Raises:
TypeError – If inventory_id is not of type int
- get_inventory(name: str) dict [source]
Get all instances of an inventory by name
- Parameters:
name (str) – The inventory name
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If name is not of type str
- get_inventory_id(name: str) int [source]
Get the id of an inventory if one exists
- Parameters:
name (str) – The name of the inventory
- Return type:
int
- Returns:
The id of the inventory
- Raises:
ValueError – If zero or more than one instance is found
TypeError – If name is not of type str
- inventories_uri = '/inventories/'
- update_inventory(inventory_id: int, inventory: InventoryRequestSchema) dict [source]
Update inventory
- Parameters:
inventory_id (int) – The inventory id
inventory (InventoryRequestSchema) – The inventory data
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If inventory is not a InventoryRequestSchema
TypeError – If inventory_id is not of type int
ansible_aap_api_client.inventory_management module
AAP API client for inventory management
- class ansible_aap_api_client.inventory_management.InventoryBuilder(base_url: str, username: str, password: str, ssl_verify: bool | str, inventory: InventoryRequestSchema)[source]
Bases:
Runable
,InventoryManagement
Inventory builder class, this builds an inventory with groups and hosts
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Union[bool, str]) – The SSL verification True or False or a path to a certificate
- Raises:
TypeError – If inventory is not an instance of InventoryRequestSchema
- EOS_GROUP_VARS = {'ansible_become': True, 'ansible_become_method': 'enable', 'ansible_connection': 'ansible.netcommon.network_cli', 'ansible_network_os': 'eos'}
- IOSXR_GROUP_VARS = {'ansible_become': True, 'ansible_become_method': 'enable', 'ansible_connection': 'ansible.netcommon.network_cli', 'ansible_network_os': 'iosxr'}
- IOS_GROUP_VARS = {'ansible_become': True, 'ansible_become_method': 'enable', 'ansible_connection': 'ansible.netcommon.network_cli', 'ansible_network_os': 'ios'}
- NXOS_GROUP_VARS = {'ansible_become': True, 'ansible_become_method': 'enable', 'ansible_connection': 'ansible.netcommon.network_cli', 'ansible_network_os': 'nxos'}
- add_custom_group_to_inventory(group: InventoryGroupRequestSchema) None [source]
Add custom group to inventory
- Parameters:
group (InventoryGroupRequestSchema) – The group to add
- Return type:
None
- Returns:
Adds the custom group to the inventory
- Raises:
TypeError – If group is not an instance of InventoryGroupRequestSchema
- add_custom_groups_to_inventory(groups: List[InventoryGroupRequestSchema]) None [source]
Add custom group to inventory
- Parameters:
groups (List[InventoryGroupRequestSchema]) – The groups to add
- Return type:
None
- Returns:
Adds the custom groups to the inventory
- Raises:
TypeError – If groups is not a list of InventoryGroupRequestSchema
- add_eos_host_to_inventory(host: InventoryHostRequestSchema) None [source]
Add EOS host to inventory
- Parameters:
host (InventoryHostRequestSchema) – The host to add
- Return type:
None
- Returns:
Adds the host to the inventory
- Raises:
TypeError – If host is not an instance of InventoryHostRequestSchema
- add_eos_hosts_to_inventory(hosts: List[InventoryHostRequestSchema]) None [source]
Add multiple EOS hosts to inventory
- Parameters:
hosts (List[InventoryHostRequestSchema]) – The hosts to add
- Return type:
None
- Returns:
Adds the hosts to the inventory
- Raises:
TypeError – If hosts is not a list of InventoryHostRequestSchema
- add_host_to_custom_group_to_inventory(group_name: str, host: InventoryHostRequestSchema) None [source]
Add host to custom group to inventory
- Parameters:
group_name (str) – The group name to add the host to
host (InventoryHostRequestSchema) – The host to add
- Return type:
None
- Returns:
Adds the host to the inventory
- Raises:
TypeError – If group_name is not a string or host is not an instance of InventoryHostRequestSchema
- add_hosts_to_custom_group_to_inventory(group_name: str, hosts: List[InventoryHostRequestSchema]) None [source]
Add hosts to custom group to inventory
- Parameters:
group_name (str) – The group name to add the hosts to
hosts (List[InventoryHostRequestSchema]) – The hosts to add
- Return type:
None
- Returns:
Adds the hosts to the inventory
- Raises:
TypeError – If group_name is not a string or hosts is not a list of InventoryHostRequestSchema
- add_ios_host_to_inventory(host: InventoryHostRequestSchema) None [source]
Add IOS host to inventory
- Parameters:
host (InventoryHostRequestSchema) – The host to add
- Return type:
None
- Returns:
Adds the host to the inventory
- Raises:
TypeError – If host is not an instance of InventoryHostRequestSchema
- add_ios_hosts_to_inventory(hosts: List[InventoryHostRequestSchema]) None [source]
Add multiple IOS hosts to inventory
- Parameters:
hosts (List[InventoryHostRequestSchema]) – The hosts to add
- Return type:
None
- Returns:
Adds the hosts to the inventory
- Raises:
TypeError – If hosts is not a list of InventoryHostRequestSchema
- add_iosxr_host_to_inventory(host: InventoryHostRequestSchema) None [source]
Add IOS-XR host to inventory
- Parameters:
host (InventoryHostRequestSchema) – The host to add
- Return type:
None
- Returns:
Adds the host to the inventory
- Raises:
TypeError – If host is not an instance of InventoryHostRequestSchema
- add_iosxr_hosts_to_inventory(hosts: List[InventoryHostRequestSchema]) None [source]
Add multiple IOS-XR hosts to inventory
- Parameters:
hosts (List[InventoryHostRequestSchema]) – The hosts to add
- Return type:
None
- Returns:
Adds the hosts to the inventory
- Raises:
TypeError – If hosts is not a list of InventoryHostRequestSchema
- add_nxos_host_to_inventory(host: InventoryHostRequestSchema) None [source]
Add NX-OS host to inventory
- Parameters:
host (InventoryHostRequestSchema) – The host to add
- Return type:
None
- Returns:
Adds the host to the inventory
- Raises:
TypeError – If host is not an instance of InventoryHostRequestSchema
- add_nxos_hosts_to_inventory(hosts: List[InventoryHostRequestSchema]) None [source]
Add multiple NX-OS hosts to inventory
- Parameters:
hosts (List[InventoryHostRequestSchema]) – The hosts to add
- Return type:
None
- Returns:
Adds the hosts to the inventory
- Raises:
TypeError – If hosts is not a list of InventoryHostRequestSchema
- class ansible_aap_api_client.inventory_management.InventoryManagement(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
-
Inventory management class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
ansible_aap_api_client.job_management module
AAP Job Management
- class ansible_aap_api_client.job_management.JobManagement(base_url: str, username: str, password: str, ssl_verify: bool | str, job_template_name: str, inventory_name: str)[source]
Bases:
Runable
,InventoryManagement
,JobTemplate
,Job
Job management class, to run a job template against an inventory
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Union[bool, str]) – The SSL verification True or False or a path to a certificate
job_template_name (str) – The name of the job template
inventory_name (str) – The name of the inventory
- Raises:
TypeError – If job_template_name is not of type str
TypeError – If inventory_name is not of type str
- poll_completion(print_status: bool | None = False, **kwargs) str [source]
Run the job and poll the completion of a job
- Parameters:
print_status (Optional[bool] = False) – Print the status of the job
kwargs – The keyword arguments to pass to the launch_job_template method
- Return type:
String
- Returns:
The completed status of the job
- Raises:
TypeError – If print_status is not of type bool
ansible_aap_api_client.job_templates module
AAP API client for job templates
- class ansible_aap_api_client.job_templates.JobTemplate(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
Bases:
_BaseConnection
Job Templates class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
- get_job_template(name: str) dict [source]
Get all instances of a job template by name
- Parameters:
name (str) – The name of the job template
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If name is not of type str
- get_job_template_id(name: str) int [source]
Get the id of a job template if one exists
- Parameters:
name (str) – The name of the job template
- Return type:
int
- Returns:
The id of the job template
- Raises:
ValueError – If zero or more than one instance is found
TypeError – If name is not of type str
- job_templates_uri = '/job_templates/'
- launch_job_template(job_template_id: int, **kwargs) dict [source]
Launch a job template
- Parameters:
job_template_id (int) – The id of the job template
kwargs – The key word args to launch the job with, example: inventory=1, extra_vars={“key”: “value”}
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If job_template_id is not of type int
ansible_aap_api_client.jobs module
AAP Jobs
- class ansible_aap_api_client.jobs.Job(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
Bases:
_BaseConnection
Job class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
- get_job(job_id: int) dict [source]
Get a job by id
- Parameters:
job_id (int) – The ID of the job
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If name is not of type str
- get_job_status(job_id: int) str [source]
Get the status of a job by id
- Parameters:
job_id (int) – The ID of the job
- Return type:
str
- Returns:
The status of the job
- Raises:
TypeError – If name is not of type str
- get_job_stdout(job_id: int, output_format: Literal['txt', 'json', 'html'] | None = 'txt') str [source]
Get the stdout of a job by id, this is the ansible run log
- Parameters:
job_id (int) – The ID of the job
output_format (Optional[Literal["txt", "json", "html"]] = "txt") – The format of the output
- Return type:
str
- Returns:
The stdout of the job
- Raises:
TypeError – If name is not of type str
- jobs_uri = '/jobs/'
ansible_aap_api_client.organizations module
AAP API client for organizations
- class ansible_aap_api_client.organizations.Organization(base_url: str, username: str, password: str, ssl_verify: bool | str | None = True)[source]
Bases:
_BaseConnection
Organization class
- Parameters:
base_url (str) – The base url to use
username (str) – The username to use
password (str) – The password to use
ssl_verify (Optional[Union[bool, str]] = True) – The SSL verification True or False or a path to a certificate
- create_organization(organization: OrganizationRequestSchema)[source]
Create an organization
- Parameters:
organization (OrganizationRequestSchema) – The organization object
- Return type:
dict
- Returns:
The created organization
- Raises:
TypeError – If organization is not of type OrganizationRequestSchema
- delete_organization(organization_id: int) int [source]
Delete organization
- Parameters:
organization_id (int) – The id of the organization
- Return type:
Integer
- Returns:
Response Status Code
- Raises:
TypeError – If organization_id is not of type int
- get_organization(name: str) dict [source]
Get all instances of an organization by name
- Parameters:
name (str) – The name of the organization
- Return type:
Dict
- Returns:
Response
- Raises:
TypeError – If name is not of type str
- get_organization_id(name: str) int [source]
Get the id of an organization if one exists
- Parameters:
name (str) – The name of the organization
- Return type:
int
- Returns:
The id of the organization
- Raises:
ValueError – If zero or more than one instance is found
TypeError – If name is not of type str
- organizations_uri = '/organizations/'
- update_organization(organization_id: int, organization: OrganizationRequestSchema) dict [source]
Update a organization
- Parameters:
organization_id (int) – The id of the OrganizationRequestSchema
organization (InventoryHostRequestSchema) – The organization object
- Return type:
dict
- Returns:
The updated host
- Raises:
TypeError – If organization_id is not of type int
TypeError – If organization is not of type OrganizationRequestSchema
ansible_aap_api_client.schemas module
Data schemas
- class ansible_aap_api_client.schemas.InventoryGroupRequestSchema(name: str, description: str, variables: str | dict | None = '---')[source]
Bases:
_BaseSchema
Inventory Group Request Schema
- Variables:
name – Name of the Group
description – Description of the Group
variables – Variables of the group in JSON or YAML format
- description: str
- name: str
- variables: str | dict | None = '---'
- class ansible_aap_api_client.schemas.InventoryHostRequestSchema(name: str, description: str, enabled: bool | None = True, instance_id: str | None = '', variables: str | dict | None = '---')[source]
Bases:
_BaseSchema
Inventory Host Request Schema
- Variables:
name – Name of the Host
description – Description of the Host
enabled – Whether to enable the Host
instance_id – Instance ID of the Host
variables – Variables of the host in JSON or YAML format
- description: str
- enabled: bool | None = True
- instance_id: str | None = ''
- name: str
- variables: str | dict | None = '---'
- class ansible_aap_api_client.schemas.InventoryRequestSchema(name: str, description: str, organization: int, kind: str | None = '', host_filter: str | None = None, variables: str | dict | None = '---', prevent_instance_group_fallback: bool | None = False)[source]
Bases:
_BaseSchema
Inventory Request Schema
- Variables:
name – Name of the Inventory
description – Description of the Inventory
organization – Organization the Inventory belongs to
kind – Kind of the Inventory
host_filter – Host filter of the Inventory
variables – Variables of the all group of the Inventory in JSON or YAML format
prevent_instance_group_fallback – Whether to prevent fallback
- description: str
- host_filter: str | None = None
- kind: str | None = ''
- name: str
- organization: int
- prevent_instance_group_fallback: bool | None = False
- variables: str | dict | None = '---'
- class ansible_aap_api_client.schemas.JobTemplateRequestSchema(name: str | None = '', description: str | None = '', job_type: Literal['run', 'check'] | None = 'run', inventory: int | None = None, project: int | None = None, playbook: str | None = '', scm_branch: str | None = '', forks: int | None = 0, limit: str | None = '', verbosity: Literal[0, 1, 2, 3, 4, 5] | None = 0, extra_vars: str | None = '', job_tags: str | None = '', force_handlers: bool | None = False, skip_tags: str | None = '', start_at_task: str | None = '', timeout: int | None = 0, use_fact_cache: bool | None = False, execution_environment: int | None = None, host_config_key: str | None = '', ask_scm_branch_on_launch: bool | None = False, ask_diff_mode_on_launch: bool | None = False, ask_variables_on_launch: bool | None = False, ask_limit_on_launch: bool | None = False, ask_tags_on_launch: bool | None = False, ask_skip_tags_on_launch: bool | None = False, ask_job_type_on_launch: bool | None = False, ask_verbosity_on_launch: bool | None = False, ask_inventory_on_launch: bool | None = False, ask_credential_on_launch: bool | None = False, ask_execution_environment_on_launch: bool | None = False, ask_labels_on_launch: bool | None = False, ask_forks_on_launch: bool | None = False, ask_job_slice_count_on_launch: bool | None = False, ask_timeout_on_launch: bool | None = False, ask_instance_groups_on_launch: bool | None = False, survey_enabled: bool | None = False, become_enabled: bool | None = False, diff_mode: bool | None = False, allow_simultaneous: bool | None = False, job_slice_count: int | None = 1, webhook_service: Literal['', 'github', 'gitlab', 'bitbucket_dc'] | None = None, webhook_credential: int | None = None, prevent_instance_group_fallback: bool | None = False)[source]
Bases:
_BaseSchema
Job Template Request Schema
- allow_simultaneous: bool | None = False
- ask_credential_on_launch: bool | None = False
- ask_diff_mode_on_launch: bool | None = False
- ask_execution_environment_on_launch: bool | None = False
- ask_forks_on_launch: bool | None = False
- ask_instance_groups_on_launch: bool | None = False
- ask_inventory_on_launch: bool | None = False
- ask_job_slice_count_on_launch: bool | None = False
- ask_job_type_on_launch: bool | None = False
- ask_labels_on_launch: bool | None = False
- ask_limit_on_launch: bool | None = False
- ask_scm_branch_on_launch: bool | None = False
- ask_skip_tags_on_launch: bool | None = False
- ask_tags_on_launch: bool | None = False
- ask_timeout_on_launch: bool | None = False
- ask_variables_on_launch: bool | None = False
- ask_verbosity_on_launch: bool | None = False
- become_enabled: bool | None = False
- description: str | None = ''
- diff_mode: bool | None = False
- execution_environment: int | None = None
- extra_vars: str | None = ''
- force_handlers: bool | None = False
- forks: int | None = 0
- host_config_key: str | None = ''
- inventory: int | None = None
- job_slice_count: int | None = 1
- job_tags: str | None = ''
- job_type: Literal['run', 'check'] | None = 'run'
- limit: str | None = ''
- name: str | None = ''
- playbook: str | None = ''
- prevent_instance_group_fallback: bool | None = False
- project: int | None = None
- scm_branch: str | None = ''
- skip_tags: str | None = ''
- start_at_task: str | None = ''
- survey_enabled: bool | None = False
- timeout: int | None = 0
- use_fact_cache: bool | None = False
- verbosity: Literal[0, 1, 2, 3, 4, 5] | None = 0
- webhook_credential: int | None = None
- webhook_service: Literal['', 'github', 'gitlab', 'bitbucket_dc'] | None = None
- class ansible_aap_api_client.schemas.OrganizationRequestSchema(name: str, description: str, max_hosts: int | None = 0, default_environment: int | None = None)[source]
Bases:
_BaseSchema
Organization Request Schema
- Variables:
name – Name of the Group
description – Description of the Group
max_hosts – The maximum hosts 0 means unlimited
default_environment – The id of the execution environment
- default_environment: int | None = None
- description: str
- max_hosts: int | None = 0
- name: str
ansible_aap_api_client.version module
Holds the version information for the package
Module contents
init for ansible_aap_api_client