### Setup Ansible Development Environment Source: https://docs.ansible.com/projects/ansible/2.10/dev_guide/developing_modules_general.html Commands to clone the repository, initialize a Python virtual environment, and prepare the development shell. ```bash git clone https://github.com/ansible/ansible.git cd ansible python3 -m venv venv . venv/bin/activate pip install -r requirements.txt . hacking/env-setup ``` -------------------------------- ### Start Instance - Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/ngine_io/cloudstack/cs_instance_module.html This example demonstrates how to ensure a specific instance is in a started (running) state. It requires the instance name and setting the state to 'started'. ```yaml - name: ensure an instance is running ngine_io.cloudstack.cs_instance: name: web-vm-1 state: started ``` -------------------------------- ### Start Proxmox Container (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/proxmox_module.html This example shows how to start a Proxmox container using the community.general.proxmox module. ```yaml - name: Start container community.general.proxmox: vmid: 100 api_user: root@pam api_password: 1q2w3e api_host: node1 state: started ``` -------------------------------- ### Setup and Install Resource Module Builder Source: https://docs.ansible.com/projects/ansible/2.10/network/dev_guide/developing_resource_modules_network.html Commands to clone the resource module builder repository from GitHub and install the necessary Python dependencies. ```bash git clone https://github.com/ansible-network/resource_module_builder.git pip install -r requirements.txt ``` -------------------------------- ### Start Virtual Machine with Kubevirt VM Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/kubevirt_vm_module.html This example demonstrates how to start a virtual machine named 'myvm' in the 'vms' namespace using the `kubevirt_vm` module. It sets the desired state to 'running'. ```yaml - name: Start virtual machine 'myvm' community.general.kubevirt_vm: state: running name: myvm namespace: vms ``` -------------------------------- ### Start Proxmox VM (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/proxmox_kvm_module.html This example demonstrates how to start a Proxmox KVM virtual machine that is currently stopped. It requires the API credentials, host, VM name, and node, and sets the 'state' parameter to 'started'. ```yaml - name: Start VM community.general.proxmox_kvm: api_user: root@pam api_password: secret api_host: helldorado name: spynal node: sabrewulf state: started ``` -------------------------------- ### Ansible: Create a VM and start it after creation in Foreman Source: https://docs.ansible.com/projects/ansible/2.10/collections/theforeman/foreman/host_module.html This example demonstrates creating a virtual machine and configuring it to start immediately after its creation in Foreman. The 'start' parameter within 'compute_attributes' is set to '1'. ```yaml - name: "Create a VM and start it after creation" theforeman.foreman.host: username: "admin" password: "changeme" server_url: "https://foreman.example.com" name: "new_host" compute_attributes: start: "1" state: present ``` -------------------------------- ### Start Fedora VM with Cloud-Init using Kubevirt VM Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/kubevirt_vm_module.html This example starts a Fedora virtual machine with cloud-init user data for initial configuration, including setting a password. It waits for the VM to be running and specifies memory and disk details. ```yaml - name: Start fedora vm with cloud init community.general.kubevirt_vm: state: running wait: true name: myvm namespace: vms memory: 1024M cloud_init_nocloud: userData: |- #cloud-config password: fedora chpasswd: { expire: False } disks: - name: containerdisk volume: containerDisk: image: kubevirt/fedora-cloud-container-disk-demo:latest path: /disk/fedora.qcow2 disk: bus: virtio node_affinity: soft: - weight: 1 term: match_expressions: - key: security operator: In values: - S2 ``` -------------------------------- ### Start a Server with clc_server Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/clc_server_module.html This example shows how to start a specific server identified by its ID using the `community.general.clc_server` module. The `state: started` parameter is crucial for this operation. Proper authentication and server ID are necessary. ```yaml - name: Start a Server community.general.clc_server: server_ids: - UC1ACCT-TEST01 state: started ``` -------------------------------- ### Install and Uninstall Packages with win_package Source: https://docs.ansible.com/projects/ansible/2.10/collections/ansible/windows/win_package_module.html Examples demonstrating how to install software from remote URLs or local paths, handle arguments, and perform uninstallation using product IDs. These tasks utilize the ansible.windows.win_package module to manage Windows software lifecycle. ```yaml - name: Install the Visual C thingy ansible.windows.win_package: path: http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe product_id: '{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}' arguments: /install /passive /norestart - name: Install Visual C thingy with list of arguments instead of a string ansible.windows.win_package: path: http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe product_id: '{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}' arguments: - /install - /passive - /norestart - name: Install Remote Desktop Connection Manager from msi with a permanent log ansible.windows.win_package: path: https://download.microsoft.com/download/A/F/0/AF0071F3-B198-4A35-AA90-C68D103BDCCF/rdcman.msi product_id: '{0240359E-6A4C-4884-9E94-B397A02D893C}' state: present log_path: D:\logs\vcredist_x64-exe-{{lookup('pipe', 'date +%Y%m%dT%H%M%S')}}.log - name: Uninstall Remote Desktop Connection Manager ansible.windows.win_package: product_id: '{0240359E-6A4C-4884-9E94-B397A02D893C}' state: absent - name: Install Remote Desktop Connection Manager locally omitting the product_id ansible.windows.win_package: path: C:\temp\rdcman.msi state: present - name: Uninstall Remote Desktop Connection Manager from local MSI omitting the product_id ansible.windows.win_package: path: C:\temp\rdcman.msi state: absent ``` -------------------------------- ### Install a package using win_scoop Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/windows/win_scoop_module.html This example demonstrates how to install a package named 'jq' using the community.windows.win_scoop module. It assumes Scoop is already installed or will be installed by the module. ```yaml - name: Install jq. community.windows.win_scoop: name: jq ``` -------------------------------- ### Install WebDAV client feature using win_feature Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/windows/win_mapped_drive_module.html This example demonstrates how to ensure the WebDAV client feature (WebDAV-Redirector) is installed on a Windows system using the `win_feature` module. This is a prerequisite for mapping WebDAV locations. The `register` keyword captures the result, including whether a reboot is required. ```yaml # This should only be required for Windows Server OS' - name: Ensure WebDAV client feature is installed ansible.windows.win_feature: name: WebDAV-Redirector state: present register: webdav_feature ``` -------------------------------- ### Start Proxmox Container with Timeout (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/proxmox_module.html This example demonstrates starting a Proxmox container with a specified timeout, which is useful for containers with additional disks that may take longer to boot. ```yaml - name: > Start container with mount. You should enter a 90-second timeout because servers with additional disks take longer to boot community.general.proxmox: vmid: 100 api_user: root@pam api_password: 1q2w3e api_host: node1 state: started timeout: 90 ``` -------------------------------- ### Install software packages on Junos devices using Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/junipernetworks/junos/junos_package_module.html Demonstrates how to use the junos_package module to install software packages from a local source. Includes examples for standard installation, disabling automatic reboots, and specifying custom SSH configurations. ```yaml - name: install local package on remote device junipernetworks.junos.junos_package: src: junos-vsrx-12.1X46-D10.2-domestic.tgz - name: install local package on remote device without rebooting junipernetworks.junos.junos_package: src: junos-vsrx-12.1X46-D10.2-domestic.tgz reboot: no - name: install local package on remote device with jumpost junipernetworks.junos.junos_package: src: junos-vsrx-12.1X46-D10.2-domestic.tgz ssh_config: /home/user/customsshconfig ``` -------------------------------- ### Start Ephemeral VM with Wait and Timeout using Kubevirt VM Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/kubevirt_vm_module.html This example starts an ephemeral virtual machine named 'myvm', waits for it to be running, and specifies a `wait_timeout` of 180 seconds. It also includes memory, labels, and disk configuration. ```yaml - name: Start ephemeral virtual machine 'myvm' and wait to be running community.general.kubevirt_vm: ephemeral: true state: running wait: true wait_timeout: 180 name: myvm namespace: vms memory: 64M labels: kubevirt.io/vm: myvm disks: - name: containerdisk volume: containerDisk: image: kubevirt/cirros-container-disk-demo:latest path: /custom-disk/cirros.img disk: bus: virtio ``` -------------------------------- ### Start EC2 Instances by Tag with Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/amazon/aws/ec2_module.html This example demonstrates how to start EC2 instances based on their tags. It uses the `amazon.aws.ec2` module with `instance_tags` to filter instances and sets the `state` to `running`. This is useful for starting a group of related instances efficiently. ```yaml - amazon.aws.ec2: instance_tags: Name: ExtraPower state: running ``` -------------------------------- ### Install Python libraries using easy_install Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/easy_install_module.html Examples demonstrating how to install or update Python packages like pip and how to target specific virtual environments using the community.general.easy_install module. ```yaml - name: Install or update pip community.general.easy_install: name: pip state: latest - name: Install Bottle into the specified virtualenv community.general.easy_install: name: bottle virtualenv: /webapps/myapp/venv ``` -------------------------------- ### Create and Start Virtual Machine with Kubevirt VM Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/kubevirt_vm_module.html This example shows how to create a virtual machine named 'myvm' with specific configurations like memory, CPU cores, bootloader, and network interfaces, and then start it. It utilizes parameters such as `memory`, `cpu_cores`, `bootloader`, `smbios_uuid`, `cpu_model`, `headless`, `hugepage_size`, `tablets`, `cpu_limit`, `cpu_shares`, and `disks`. ```yaml - name: Create virtual machine 'myvm' and start it community.general.kubevirt_vm: state: running name: myvm namespace: vms memory: 64Mi cpu_cores: 1 bootloader: efi smbios_uuid: 5d307ca9-b3ef-428c-8861-06e72d69f223 cpu_model: Conroe headless: true hugepage_size: 2Mi tablets: - bus: virtio name: tablet1 cpu_limit: 3 cpu_shares: 2 disks: - name: containerdisk volume: containerDisk: image: kubevirt/cirros-container-disk-demo:latest path: /custom-disk/cirros.img disk: bus: virtio ``` -------------------------------- ### Get whoami information using ansible.windows.win_whoami Source: https://docs.ansible.com/projects/ansible/2.10/collections/ansible/windows/win_whoami_module.html This example demonstrates how to use the ansible.windows.win_whoami module to retrieve current user and process details. Ensure the ansible.windows collection is installed. ```yaml - name: Get whoami information ansible.windows.win_whoami: ``` -------------------------------- ### Compare Startup Config Against Running Config Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/network/voss_config_module.html This example demonstrates comparing the startup configuration against the running configuration, with an option to ignore specific lines during the comparison using 'diff_ignore_lines'. ```yaml - name: Check the startup-config against the running-config community.network.voss_config: diff_against: startup diff_ignore_lines: - qos queue-profile .* ``` -------------------------------- ### Install Ansible Module Prerequisites on Ubuntu Source: https://docs.ansible.com/projects/ansible/2.10/dev_guide/developing_modules_general.html Installs necessary build tools and development libraries on Ubuntu systems required for developing Ansible modules. These include packages for building, SSL, FFI, and Python development. ```bash sudo apt update sudo apt install build-essential libssl-dev libffi-dev python-dev ``` -------------------------------- ### Integrate Module into Ansible Playbook Source: https://docs.ansible.com/projects/ansible/2.10/dev_guide/developing_modules_general.html An example YAML playbook demonstrating how to invoke a custom module and register its output for debugging purposes. ```yaml - name: test my new module hosts: localhost tasks: - name: run the new module my_test: name: 'hello' new: true register: testout - name: dump test output debug: msg: '{{ testout }}' ``` -------------------------------- ### Ansible Command-Line Examples: Gathering Facts Source: https://docs.ansible.com/projects/ansible/2.10/collections/ansible/builtin/setup_module.html These examples show how to use the ansible.builtin.setup module directly from the command line. They cover displaying all facts, filtering facts by a wildcard pattern, displaying only facts returned by 'facter', and collecting a specific subset of facts. ```bash # Display facts from all hosts and store them indexed by I(hostname) at C(/tmp/facts). # ansible all -m ansible.builtin.setup --tree /tmp/facts ``` ```bash # Display only facts regarding memory found by ansible on all hosts and output them. # ansible all -m ansible.builtin.setup -a 'filter=ansible_*_mb' ``` ```bash # Display only facts returned by facter. # ansible all -m ansible.builtin.setup -a 'filter=facter_*' ``` ```bash # Collect only facts returned by facter. # ansible all -m ansible.builtin.setup -a 'gather_subset=!all,!any,facter' ``` -------------------------------- ### Ansible Playbook Example: Get Quay.io Login Info Source: https://docs.ansible.com/projects/ansible/2.10/collections/containers/podman/podman_login_info_module.html This example shows how to use the containers.podman.podman_login_info module in an Ansible playbook to fetch login details for the quay.io registry. Ensure the 'containers.podman' collection is installed before execution. ```yaml - name: Return the logged-in user for quay.io registry containers.podman.podman_login_info: registry: quay.io ``` -------------------------------- ### Ansible Playbook Example: Get Docker Hub Login Info Source: https://docs.ansible.com/projects/ansible/2.10/collections/containers/podman/podman_login_info_module.html This example demonstrates how to use the containers.podman.podman_login_info module in an Ansible playbook to retrieve login information for the Docker Hub registry. It requires the 'containers.podman' collection to be installed. ```yaml - name: Return the logged-in user for docker hub registry containers.podman.podman_login_info: registry: docker.io ``` -------------------------------- ### Ansible Playbook Examples for ce_startup Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/network/ce_startup_module.html Demonstrates various ways to use the community.network.ce_startup module in Ansible playbooks. It includes examples for displaying startup information, setting patch files, software files, and configuration files for the next startup on HUAWEI CloudEngine switches. ```yaml - name: Startup module test hosts: cloudengine connection: local gather_facts: no vars: cli: host: "{{ inventory_hostname }}" port: "{{ ansible_ssh_port }}" username: "{{ username }}" password: "{{ password }}" transport: cli tasks: - name: Display startup information community.network.ce_startup: action: display provider: "{{ cli }}" - name: Set startup patch file community.network.ce_startup: patch_file: 2.PAT slot: all provider: "{{ cli }}" - name: Set startup software file community.network.ce_startup: software_file: aa.cc slot: 1 provider: "{{ cli }}" - name: Set startup cfg file community.network.ce_startup: cfg_file: 2.cfg slot: 1 provider: "{{ cli }}" ``` -------------------------------- ### Get Threat Layer Facts (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/check_point/mgmt/cp_mgmt_threat_layer_facts_module.html This example demonstrates how to retrieve a specific threat layer's facts by its name using the `cp_mgmt_threat_layer_facts` module in Ansible. It requires the `check_point.mgmt` collection to be installed. ```yaml - name: show-threat-layer cp_mgmt_threat_layer_facts: name: New Layer 1 ``` -------------------------------- ### Get Task Facts using checkpoint_task_facts Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/check_point/mgmt/checkpoint_task_facts_module.html This example demonstrates how to use the checkpoint_task_facts module to retrieve facts for a specific task ID on a Check Point device. Ensure the check_point.mgmt collection is installed. ```yaml - name: Get task facts checkpoint_task_facts: task_id: 2eec70e5-78a8-4bdb-9a76-cfb5601d0bcb ``` -------------------------------- ### Action Plugin Example: Calculating Time Difference (Python) Source: https://docs.ansible.com/projects/ansible/2.10/dev_guide/developing_plugins.html A complete example of an Ansible action plugin that calculates the time difference between the Ansible controller and target machines. It uses the 'setup' module to gather remote date/time information and compares it with the local time. ```python #!/usr/bin/python # Make coding more python3-ish, this is required for contributions to Ansible from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.plugins.action import ActionBase from datetime import datetime class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): super(ActionModule).run(tmp, task_vars) module_args = self._task.args.copy() module_return = self._execute_module(module_name='setup', module_args=module_args, task_vars=task_vars, tmp=tmp) ret = dict() remote_date = None if not module_return.get('failed'): for key, value in module_return['ansible_facts'].items(): if key == 'ansible_date_time': remote_date = value['iso8601'] if remote_date: remote_date_obj = datetime.strptime(remote_date, '%Y-%m-%dT%H:%M:%SZ') time_delta = datetime.now() - remote_date_obj ret['delta_seconds'] = time_delta.seconds ret['delta_days'] = time_delta.days ret['delta_microseconds'] = time_delta.microseconds return dict(ansible_facts=dict(ret)) ``` -------------------------------- ### Create VMSS with Plan Information (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/azure/azcollection/azure_rm_virtualmachinescaleset_module.html This Ansible example shows how to create a VMSS when the chosen image requires specific plan information. It extends the basic VMSS creation by including `plan` details such as name, product, and publisher, alongside other standard VMSS parameters. ```ansible - name: Create VMSS with an image that requires plan information azure_rm_virtualmachinescaleset: resource_group: myResourceGroup name: testvmss vm_size: Standard_DS1_v2 capacity: 3 virtual_network_name: testvnet upgrade_policy: Manual subnet_name: testsubnet admin_username: adminUser ssh_password_enabled: false ssh_public_keys: - path: /home/adminUser/.ssh/authorized_keys key_data: < insert yor ssh public key here... > managed_disk_type: Standard_LRS image: offer: cis-ubuntu-linux-1804-l1 publisher: center-for-internet-security-inc sku: Stable version: latest plan: name: cis-ubuntu-linux-1804-l1 product: cis-ubuntu-linux-1804-l1 publisher: center-for-internet-security-inc data_disks: - lun: 0 disk_size_gb: 64 caching: ReadWrite managed_disk_type: Standard_LRS ``` -------------------------------- ### Vultr Account Info Module Usage Example Source: https://docs.ansible.com/projects/ansible/2.10/scenario_guides/guide_vultr.html Shows how to use the `vultr_account_info` Ansible module to retrieve account details from Vultr. This serves as a basic authentication and setup verification step. ```bash #> VULTR_API_KEY=XXX ansible -m vultr_account_info localhost ``` -------------------------------- ### Manage Service State with win_nssm Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/windows/win_nssm_module.html This playbook illustrates how to manage the state of a Windows service using the `community.windows.win_nssm` module. It shows examples of ensuring a service is present, started, stopped, or restarted. ```yaml - name: Ensure service is present and started community.windows.win_nssm: name: "Myapp" state: started - name: Ensure service is stopped community.windows.win_nssm: name: "Myapp" state: stopped - name: Ensure service is absent community.windows.win_nssm: name: "Myapp" state: absent ``` -------------------------------- ### Create and Attach Disk to VM using ovirt_disk Source: https://docs.ansible.com/projects/ansible/2.10/collections/ovirt/ovirt/ovirt_disk_module.html This example demonstrates how to create a new disk with specified properties (name, size, format, interface, storage domain) and attach it to a virtual machine. It utilizes the `ovirt_disk` module for these operations. ```yaml - ovirt.ovirt.ovirt_disk: name: myvm_disk vm_name: rhel7 size: 10GiB format: cow interface: virtio storage_domain: data ``` -------------------------------- ### Configure EXOS network devices using Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/network/exos_config_module.html Examples demonstrating how to apply configuration lines, perform diff checks against intended or startup configurations, and manage backup settings for EXOS devices. ```yaml - name: Configure SNMP system name community.network.exos_config: lines: configure snmp sysName "{{ inventory_hostname }}" - name: Configure interface settings community.network.exos_config: lines: - configure ports 2 description-string "Master Uplink" backup: yes - name: Check the running-config against master config community.network.exos_config: diff_against: intended intended_config: "{{ lookup('file', 'master.cfg') }}" - name: Check the startup-config against the running-config community.network.exos_config: diff_against: startup diff_ignore_lines: - ntp clock .* - name: Save running to startup when modified community.network.exos_config: save_when: modified - name: Configurable backup path community.network.exos_config: lines: - configure ports 2 description-string "Master Uplink" backup: yes backup_options: filename: backup.cfg dir_path: /home/user ``` -------------------------------- ### Manage GlusterFS Volumes with Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/gluster_volume_module.html Examples demonstrating how to use the gluster_volume module to create, tune, start, stop, and remove GlusterFS volumes. These tasks require the GlusterFS CLI tools to be installed on the target servers. ```yaml - name: Create gluster volume community.general.gluster_volume: state: present name: test1 bricks: /bricks/brick1/g1 rebalance: yes cluster: - 192.0.2.10 - 192.0.2.11 run_once: true - name: Tune community.general.gluster_volume: state: present name: test1 options: performance.cache-size: 256MB - name: Set multiple options on GlusterFS volume community.general.gluster_volume: state: present name: test1 options: { performance.cache-size: 128MB, write-behind: 'off', quick-read: 'on' } - name: Start gluster volume community.general.gluster_volume: state: started name: test1 - name: Limit usage community.general.gluster_volume: state: present name: test1 directory: /foo quota: 20.0MB - name: Stop gluster volume community.general.gluster_volume: state: stopped name: test1 - name: Remove gluster volume community.general.gluster_volume: state: absent name: test1 ``` -------------------------------- ### Example Usage Source: https://docs.ansible.com/projects/ansible/2.10/collections/ovirt/ovirt/ovirt_nic_module.html Illustrative examples demonstrating how to use the oVirt Ansible module for common tasks, excluding authentication parameters for brevity. ```APIDOC ## Example Usage ### Description Illustrative examples demonstrating how to use the oVirt Ansible module for common tasks, excluding authentication parameters for brevity. ### Examples ```yaml # Example 1: Ensure a network interface is present on a VM - name: Ensure network interface 'eth0' is present on VM 'my_vm' ovirt_vnic_profile: vm: my_vm name: eth0 interface: virtio network: ovirtmgmt state: present # Example 2: Remove a network interface from a VM - name: Remove network interface 'eth1' from VM 'another_vm' ovirt_vnic_profile: vm: another_vm name: eth1 state: absent # Example 3: Plug an existing network interface - name: Plug network interface 'eth2' on VM 'vm_with_nic' ovirt_vnic_profile: vm: vm_with_nic name: eth2 state: plugged # Example 4: Unplug a network interface - name: Unplug network interface 'eth3' on VM 'vm_to_unplug' ovirt_vnic_profile: vm: vm_to_unplug name: eth3 state: unplugged # Example 5: Manage NIC on a template - name: Ensure network interface 'template_nic' is present on template 'my_template' ovirt_vnic_profile: template: my_template name: template_nic interface: e1000 state: present ``` ``` -------------------------------- ### Manage WTI device users with Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/wti/remote/cpm_user_module.html Examples showing how to perform CRUD operations (Get, Add, Edit, Delete) on WTI device users using the cpm_user module. Requires the wti.remote collection to be installed. ```yaml # Get User Parameters - name: Get the User Parameters for the given user of a WTI device cpm_user: cpm_action: "getuser" cpm_url: "rest.wti.com" cpm_username: "restuser" cpm_password: "restfuluserpass12" use_https: true validate_certs: true user_name: "usernumberone" # Create User - name: Create a User on a given WTI device cpm_user: cpm_action: "adduser" cpm_url: "rest.wti.com" cpm_username: "restuser" cpm_password: "restfuluserpass12" use_https: true validate_certs: false user_name: "usernumberone" user_pass: "complicatedpassword" user_accesslevel: 2 user_accessssh: 1 user_accessserial: 1 user_accessweb: 0 user_accessapi: 1 user_accessmonitor: 0 user_accessoutbound: 0 user_portaccess: "10011111" user_plugaccess: "00000111" user_groupaccess: "00000000" # Edit User - name: Edit a User on a given WTI device cpm_user: cpm_action: "edituser" cpm_url: "rest.wti.com" cpm_username: "restuser" cpm_password: "restfuluserpass12" use_https: true validate_certs: false user_name: "usernumberone" user_pass: "newpasswordcomplicatedpassword" # Delete User - name: Delete a User from a given WTI device cpm_user: cpm_action: "deleteuser" cpm_url: "rest.wti.com" cpm_username: "restuser" cpm_password: "restfuluserpass12" use_https: true validate_certs: true user_name: "usernumberone" ``` -------------------------------- ### Get QRadar Rule Info by Name Source: https://docs.ansible.com/projects/ansible/2.10/collections/ibm/qradar/rule_info_module.html This example demonstrates how to retrieve information about a specific QRadar Rule using its name. It registers the output for further inspection. The module requires the `ibm.qradar` collection to be installed. ```yaml - name: Get information about the Rule named "Custom Company DDoS Rule" ibm.qradar.rule_info: name: "Custom Company DDoS Rule" register: custom_ddos_rule_info - name: debugging output of the custom_ddos_rule_info registered variable debug: var: custom_ddos_rule_info ``` -------------------------------- ### Setup Dependencies and Authentication for Packet.net Source: https://docs.ansible.com/projects/ansible/2.10/scenario_guides/guide_packet.html Commands to install the required Python library and configure authentication for the Packet API. The API token is set as an environment variable to allow Ansible modules to communicate with the Packet infrastructure. ```bash pip install packet-python export PACKET_API_TOKEN=Bfse9F24SFtfs423Gsd3ifGsd43sSdfs ``` -------------------------------- ### Manage oVirt Virtual Machines with Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/ovirt/ovirt/ovirt_vm_module.html Examples demonstrating how to create new VMs from templates, register existing VMs from storage domains, and configure advanced mappings for VNICs, roles, and LUNs. ```yaml - name: Creates a new Virtual Machine from template named 'rhel7_template' ovirt.ovirt.ovirt_vm: state: present name: myvm template: rhel7_template cluster: mycluster - name: Register VM ovirt.ovirt.ovirt_vm: state: registered storage_domain: mystorage cluster: mycluster name: myvm - name: Register VM with vnic profile mappings and reassign bad macs ovirt.ovirt.ovirt_vm: state: registered storage_domain: mystorage cluster: mycluster id: 1111-1111-1111-1111 vnic_profile_mappings: - source_network_name: mynetwork source_profile_name: mynetwork target_profile_id: 3333-3333-3333-3333 reassign_bad_macs: "True" - name: Creates a stateless VM which will always use latest template version ovirt.ovirt.ovirt_vm: name: myvm template: rhel7 cluster: mycluster use_latest_template_version: true - ovirt.ovirt.ovirt_vm: state: present cluster: brq01 name: myvm memory: 2GiB cpu_cores: 2 cpu_sockets: 2 disks: - name: rhel7_disk bootable: True nics: - name: nic1 ``` -------------------------------- ### Create Proxmox VM with Cloud-Init User/Password (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/general/proxmox_kvm_module.html This example demonstrates creating a Proxmox VM configured with cloud-init for initial setup, including a username, password, domain search, nameservers, network interface, and IP configuration. It uses the 'ide' parameter for cloud-init disk and specifies 'ciuser', 'cipassword', 'searchdomains', 'nameservers', 'net', and 'ipconfig'. ```yaml - name: Create new VM using cloud-init with a username and password community.general.proxmox_kvm: node: sabrewulf api_user: root@pam api_password: secret api_host: helldorado name: spynal ide: ide2: 'local:cloudinit,format=qcow2' ciuser: mylinuxuser cipassword: supersecret searchdomains: 'mydomain.internal' nameservers: 1.1.1.1 net: net0: 'virtio,bridge=vmbr1,tag=77' ipconfig: ipconfig0: 'ip=192.168.1.1/24,gw=192.168.1.1' ``` -------------------------------- ### Create Instance from ISO - Ansible Source: https://docs.ansible.com/projects/ansible/2.10/collections/ngine_io/cloudstack/cs_instance_module.html This example demonstrates how to create a virtual machine instance using a specified ISO image. It includes parameters for instance name, ISO, hypervisor, project, zone, service offering, disk offering, disk size, and network configurations. ```yaml # NOTE: Names of offerings and ISOs depending on the CloudStack configuration. - name: create a instance from an ISO ngine_io.cloudstack.cs_instance: name: web-vm-1 iso: Linux Debian 7 64-bit hypervisor: VMware project: Integration zone: ch-zrh-ix-01 service_offering: 1cpu_1gb disk_offering: PerfPlus Storage disk_size: 20 networks: - Server Integration - Sync Integration - Storage Integration ``` -------------------------------- ### Restructuring Ansible Modules for Testability (Python) Source: https://docs.ansible.com/projects/ansible/2.10/dev_guide/testing_units_modules.html This example illustrates how to refactor an Ansible module's structure to improve testability. By separating module setup and initialization into distinct functions, it becomes easier to test argument processing and other core logic. The example shows how to define `argument_spec`, create a `setup_module_object` function, and then use these in a `main` function, enabling unit tests for module setup. ```python argument_spec = dict( # module function variables state=dict(choices=['absent', 'present', 'rebooted', 'restarted'], default='present'), apply_immediately=dict(type='bool', default=False), wait=dict(type='bool', default=False), wait_timeout=dict(type='int', default=600), allocated_storage=dict(type='int', aliases=['size']), db_instance_identifier=dict(aliases=["id"], required=True), ) def setup_module_object(): module = AnsibleAWSModule( argument_spec=argument_spec, required_if=required_if, mutually_exclusive=[['old_instance_id', 'source_db_instance_identifier', 'db_snapshot_identifier']], ) return module def main(): module = setup_module_object() validate_parameters(module) conn = setup_client(module) return_dict = run_task(module, conn) module.exit_json(**return_dict) ``` -------------------------------- ### Ansible Playbook Examples for VMware vCenter Infra Profiles Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/vmware/vmware_vc_infraprofile_info_module.html This snippet demonstrates various ways to use the `vmware_vc_infraprofile_info` module in Ansible playbooks. It covers getting information, exporting, validating, and importing infra profile configurations for VMware vCenter. Ensure you have the `community.vmware` collection installed. ```yaml - name: Get information about VC infraprofile vmware_vc_infraprofile_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' delegate_to: localhost - name: export vCenter appliance infra profile config vmware_vc_infraprofile_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' api: "export" profiles: "ApplianceManagement" delegate_to: localhost - name: validate vCenter appliance infra profile config vmware_vc_infraprofile_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' api: "validate" profiles: "ApplianceManagement" config_path: "export.json" - name: import vCenter appliance infra profile config vmware_vc_infraprofile_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' api: "import" profiles: "ApplianceManagement" config_path: "import.json" delegate_to: localhost ``` -------------------------------- ### Check Startup Config Against Running Config (Ansible) Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/network/slxos_config_module.html This example demonstrates comparing the startup configuration with the running configuration. It also shows how to ignore specific lines during the comparison using 'diff_ignore_lines'. ```yaml - name: Check the startup-config against the running-config community.network.slxos_config: diff_against: startup diff_ignore_lines: - ntp clock .* ``` -------------------------------- ### Create Ansible Facts Module Source: https://docs.ansible.com/projects/ansible/2.10/dev_guide/developing_modules_general.html This Python code provides the structure for an Ansible facts module. It includes the necessary metadata like DOCUMENTATION, EXAMPLES, and RETURN sections, which are crucial for documenting custom facts. This serves as a template for creating modules that gather system information. ```python #!/usr/bin/python # Copyright: (c) 2020, Your Name # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = r''' --- module: my_test_facts short_description: This is my test facts module version_added: "1.0.0" description: This is my longer description explaining my test facts module. author: - Your Name (@yourGitHubHandle) ''' EXAMPLES = r''' - name: Return ansible_facts my_namespace.my_collection.my_test_facts: ''' RETURN = r''' ``` -------------------------------- ### Launch Compute Instance with OpenStack Server Module Source: https://docs.ansible.com/projects/ansible/2.10/collections/openstack/cloud/server_module.html Launches a compute instance using the `openstack.cloud.server` module. This example shows basic instance creation with parameters like name, state, cloud, region, image, and flavor RAM. It also demonstrates excluding deprecated images. ```yaml - name: launch a compute instance hosts: localhost tasks: - name: launch an instance openstack.cloud.server: name: vm1 state: present cloud: mordred region_name: region-b.geo-1 image: Ubuntu Server 14.04 image_exclude: deprecated flavor_ram: 4096 ``` ```yaml - name: launch a compute instance hosts: localhost tasks: - name: launch an instance openstack.cloud.server: name: vm1 cloud: rax-dfw state: present image: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM) flavor_ram: 4096 flavor_include: Performance ``` -------------------------------- ### Install Cisco NX-OS System Image Source: https://docs.ansible.com/projects/ansible/2.10/collections/cisco/nxos/nxos_install_os_module.html Example playbook tasks demonstrating how to install a system image on an N9k device, wait for the device to reboot, and verify the installation version using assertions. ```yaml - name: Install OS on N9k check_mode: no cisco.nxos.nxos_install_os: system_image_file: nxos.7.0.3.I6.1.bin issu: desired - name: Wait for device to come back up with new image wait_for: port: 22 state: started timeout: 500 delay: 60 host: '{{ inventory_hostname }}' - name: Check installed OS for newly installed version nxos_command: commands: [show version | json] provider: '{{ connection }}' register: output - assert: that: - output['stdout'][0]['kickstart_ver_str'] == '7.0(3)I6(1)' ``` -------------------------------- ### Configure Dell OS9 devices using os9_config Source: https://docs.ansible.com/projects/ansible/2.10/collections/dellemc/os9/os9_config_module.html Examples demonstrating how to use the os9_config module to apply configuration lines, manage access lists, replace command blocks, and perform configuration backups. ```yaml - os9_config: lines: ['hostname {{ inventory_hostname }}'] provider: "{{ cli }}" - os9_config: lines: - 10 permit ip host 1.1.1.1 any log - 20 permit ip host 2.2.2.2 any log - 30 permit ip host 3.3.3.3 any log - 40 permit ip host 4.4.4.4 any log - 50 permit ip host 5.5.5.5 any log parents: ['ip access-list extended test'] before: ['no ip access-list extended test'] match: exact - os9_config: lines: - 10 permit ip host 1.1.1.1 any log - 20 permit ip host 2.2.2.2 any log - 30 permit ip host 3.3.3.3 any log - 40 permit ip host 4.4.4.4 any log parents: ['ip access-list extended test'] before: ['no ip access-list extended test'] replace: block - os9_config: lines: ['hostname {{ inventory_hostname }}'] provider: "{{ cli }}" backup: yes backup_options: filename: backup.cfg dir_path: /home/user ``` -------------------------------- ### Install wti.remote Collection Source: https://docs.ansible.com/projects/ansible/2.10/collections/wti/remote/cpm_config_backup_module.html This command installs the wti.remote collection, which includes the cpm_config_backup module. Ensure you have Ansible Galaxy installed and configured. ```bash ansible-galaxy collection install wti.remote ``` -------------------------------- ### POST /vmware/autostart Source: https://docs.ansible.com/projects/ansible/2.10/collections/community/vmware/vmware_host_auto_start_module.html Configures the auto-start and auto-stop settings for a specific virtual machine or updates the system-wide default settings on a vSphere/ESXi host. ```APIDOC ## POST /vmware/autostart ### Description Configures the auto-start and auto-stop behavior for a virtual machine or modifies the global system defaults for auto-start configurations on the target host. ### Method POST ### Endpoint /vmware/autostart ### Parameters #### Request Body - **esxi_hostname** (string) - Required - ESXi hostname where the VM resides. - **hostname** (string) - Optional - vCenter or ESXi server hostname/IP. - **name** (string) - Optional - VM name to configure. - **uuid** (string) - Optional - VM BIOS UUID. - **power_info** (dictionary) - Optional - Startup/shutdown settings (start_action, start_delay, start_order, stop_action, stop_delay, wait_for_heartbeat). - **system_defaults** (dictionary) - Optional - System-wide auto-start/stop defaults. - **username** (string) - Optional - vSphere/ESXi username. - **password** (string) - Optional - vSphere/ESXi password. ### Request Example { "esxi_hostname": "esxi01.example.com", "name": "web-server-01", "power_info": { "start_action": "powerOn", "start_delay": 30, "stop_action": "powerOff" } } ### Response #### Success Response (200) - **changed** (boolean) - Indicates if the configuration was modified. - **result** (string) - Status message of the operation. #### Response Example { "changed": true, "result": "Auto-start configuration updated successfully." } ``` -------------------------------- ### Ansible bigip_ucs Module Examples Source: https://docs.ansible.com/projects/ansible/2.10/collections/f5networks/f5_modules/bigip_ucs_module.html This snippet demonstrates various use cases for the `bigip_ucs` Ansible module. It covers uploading a UCS file, installing it with different options (like skipping license installation or platform checks), installing with a passphrase, and removing an uploaded UCS file. The examples require the `bigip_ucs` module and specify connection details via the `provider` parameter. ```yaml - name: Upload UCS bigip_ucs: ucs: /root/bigip.localhost.localdomain.ucs state: present provider: server: lb.mydomain.com user: admin password: secret delegate_to: localhost - name: Install (upload, install) UCS. bigip_ucs: ucs: /root/bigip.localhost.localdomain.ucs state: installed provider: server: lb.mydomain.com user: admin password: secret delegate_to: localhost - name: Install (upload, install) UCS without installing the license portion bigip_ucs: ucs: /root/bigip.localhost.localdomain.ucs state: installed no_license: yes provider: server: lb.mydomain.com user: admin password: secret delegate_to: localhost - name: Install (upload, install) UCS except the license, and bypassing the platform check bigip_ucs: ucs: /root/bigip.localhost.localdomain.ucs state: installed no_license: yes no_platform_check: yes provider: server: lb.mydomain.com user: admin password: secret delegate_to: localhost - name: Install (upload, install) UCS using a passphrase necessary to load the UCS bigip_ucs: ucs: /root/bigip.localhost.localdomain.ucs state: installed passphrase: MyPassphrase1234 provider: server: lb.mydomain.com user: admin password: secret delegate_to: localhost - name: Remove uploaded UCS file bigip_ucs: ucs: bigip.localhost.localdomain.ucs state: absent provider: server: lb.mydomain.com user: admin password: secret delegate_to: localhost ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.