### Ansible Module Helper Quickstart Example Source: https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_modulehelper A Python example demonstrating the basic usage of Ansible's ModuleHelper class to create a custom module. It includes argument specification and execution logic, with handling for check mode and raising errors. ```python from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper class MyTest(ModuleHelper): module = dict( argument_spec=dict( name=dict(type='str', required=True), new=dict(type='bool', required=False, default=False), ), supports_check_mode=True, ) def __run__(self): self.vars.original_message = '' self.vars.message = '' if self.check_mode: return self.vars.original_message = self.vars.name self.vars.message = 'goodbye' self.changed = self.vars['new'] if self.vars.name == "fail me": self.do_raise("You requested this to fail") def main(): MyTest.execute() if __name__ == '__main__': main() ``` -------------------------------- ### Ansible Role Tasks Example (NTP Configuration) Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Presents a sample `tasks/main.yml` file for an Ansible role, demonstrating how to configure NTP. It includes tasks for installing the NTP package, configuring the NTP service using a template, and ensuring the NTP service is running. ```yaml --- # file: roles/common/tasks/main.yml - name: be sure ntp is installed yum: name: ntp state: present tags: ntp - name: be sure ntp is configured template: src: ntp.conf.j2 dest: /etc/ntp.conf notify: - restart ntpd tags: ntp - name: be sure ntpd is running and enabled ansible.builtin.service: name: ntpd state: started enabled: true tags: ntp ``` -------------------------------- ### Ansible Playbook Examples for Simpleinit MSB Module Source: https://docs.ansible.com/ansible/latest/collections/community/general/simpleinit_msb_module Provides various Ansible playbook examples for managing services using the community.general.simpleinit_msb module. These examples cover starting, stopping, restarting, reloading, and enabling/disabling services idempotently. ```yaml - name: Example action to start service httpd, if not running community.general.simpleinit_msb: name: httpd state: started - name: Example action to stop service httpd, if running community.general.simpleinit_msb: name: httpd state: stopped - name: Example action to restart service httpd, in all cases community.general.simpleinit_msb: name: httpd state: restarted - name: Example action to reload service httpd, in all cases community.general.simpleinit_msb: name: httpd state: reloaded - name: Example action to enable service httpd, and not touch the running state community.general.simpleinit_msb: name: httpd enabled: true ``` -------------------------------- ### Start a server Source: https://docs.ansible.com/ansible/latest/collections/community/general/oneandone_server_module This example shows how to start a server. It requires the authentication token and the server identifier, with the state set to 'running'. ```yaml - name: Starting server community.general.oneandone_server: auth_token: oneandone_private_api_key state: running server: 'node01' ``` -------------------------------- ### Windows 10 VM Creation with CD-ROM Install using Ansible Source: https://docs.ansible.com/ansible/latest/collections/community/libvirt/virt_install_module This example shows how to create a Windows 10 virtual machine using a CD-ROM for installation. It includes VM name, memory, vCPUs, disk configuration, OS details, CD-ROM path, graphics with a password, and network setup. ```yaml - name: Create Windows 10 VM community.libvirt.virt_install: name: my-win10-vm memory: 4096 vcpus: 4 disks: - size: 40 format: qcow2 osinfo: name: win10 cdrom: /path/to/my/win10.iso graphics: type: vnc password: mypassword networks: - network: default model: type: e1000 ``` -------------------------------- ### Ansible Pipx Module Examples Source: https://docs.ansible.com/ansible/latest/collections/community/general/pipx_module Demonstrates various ways to use the community.general.pipx Ansible module for installing, upgrading, and managing Python packages. Includes examples for installing from Git, using specific Python versions, and handling multiple packages. ```ansible - name: Install tox community.general.pipx: name: tox - name: Install tox from git repository community.general.pipx: name: tox source: git+https://github.com/tox-dev/tox.git - name: Upgrade tox community.general.pipx: name: tox state: upgrade - name: Install or upgrade tox with extra 'docs' community.general.pipx: name: tox source: tox[docs] state: latest - name: Reinstall black with specific Python version community.general.pipx: name: black state: reinstall python: 3.7 - name: Uninstall pycowsay community.general.pipx: name: pycowsay state: absent - name: Install multiple packages from list vars: pipx_packages: - pycowsay - black - tox community.general.pipx: name: "{{ item }}" state: latest with_items: "{{ pipx_packages }}" ``` -------------------------------- ### Setup Docker Compose Environment Source: https://docs.ansible.com/ansible/latest/collections/community/hashi_vault/docsite/contributor_guide Executes the setup script to provision the Docker Compose environment, including templating configuration files and managing Docker containers. ```bash ./setup.sh ``` -------------------------------- ### Get BIOS setup using kaytus.ksmanage.bios_info Source: https://docs.ansible.com/ansible/latest/collections/kaytus/ksmanage/bios_info_module An Ansible playbook example demonstrating how to use the kaytus.ksmanage.bios_info module to retrieve BIOS setup information. It sets up connection details via variables and calls the module. ```yaml - name: Bios test hosts: ksmanage connection: local gather_facts: false vars: ksmanage: host: "{{ ansible_ssh_host }}" username: "{{ username }}" password: "{{ password }}" tasks: - name: "Get bios setup" kaytus.ksmanage.bios_info: provider: "{{ ksmanage }}" ``` -------------------------------- ### Docker SDK for Python Installation Source: https://docs.ansible.com/ansible/latest/collections/community/docker/docsite/scenario_guide Instructions for installing the Docker SDK for Python, required by most community.docker modules and plugins. ```APIDOC ## Installing Docker SDK for Python Most modules and plugins in the `community.docker` collection require the Docker SDK for Python. This SDK needs to be installed on the machines where Ansible modules and plugins are executed. ### Python 3.6+ ```bash $ pip install docker ``` ### Python 2.7 (Legacy) For Python 2.7, use a Docker SDK for Python version between 2.0.0 and 4.4.4, as version 5.0.0 and later removed Python 2.7 support. ```bash $ pip install 'docker==4.4.4' ``` **Important Note:** The Docker SDK for Python was named `docker-py` on PyPI before version 2.0.0. Avoid installing very old versions. Ensure you do not install both `docker` and `docker-py`, as this can lead to a broken installation. If you encounter issues, uninstall both and reinstall the correct version. When in doubt, always install `docker` and avoid `docker-py`. ``` -------------------------------- ### Install Application with MSI Properties Source: https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_package_module Installs a local MSI application and sets multiple properties for the installer using a multi-line string. This example demonstrates customizing the installation with specific parameters. ```yaml - name: Install Application from msi with multiple properties for installer ansible.windows.win_package: path: C:\temp\Application.msi state: present arguments: >- SERVICE=1 DBNAME=ApplicationDB DBSERVER=.\SQLEXPRESS INSTALLDIR="C:\Program Files (x86)\App lication\App Server" ``` -------------------------------- ### Ansible Playbook Import Example Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Demonstrates how to structure Ansible playbooks for managing different parts of an infrastructure. This example shows a main playbook (`site.yml`) that imports other playbooks (`webservers.yml`, `dbservers.yml`), allowing for modular and organized infrastructure definition. ```yaml --- # file: site.yml - import_playbook: webservers.yml - import_playbook: dbservers.yml ``` ```yaml --- # file: webservers.yml - hosts: webservers roles: - common - webtier ``` -------------------------------- ### Install Roles and Collections from requirements.yml Source: https://docs.ansible.com/ansible/latest/galaxy/user_guide Install Ansible roles and collections directly from a single requirements.yml file. This example shows how to specify roles and collections with versions and sources from Ansible Galaxy. ```yaml --- roles: # Install a role from Ansible Galaxy. - name: geerlingguy.java version: "1.9.6" # note that ranges are not supported for roles collections: # Install a collection from Ansible Galaxy. - name: community.general version: ">=7.0.0" source: https://galaxy.ansible.com ``` -------------------------------- ### Create and Run a Basic Ansible Playbook Source: https://docs.ansible.com/ansible/latest/getting_started/get_started_playbook Demonstrates how to create a simple Ansible playbook named 'playbook.yaml' to ping hosts and print a 'Hello world' message. It includes the playbook content and the command to execute it, along with expected output. ```yaml - name: My first play hosts: myhosts tasks: - name: Ping my hosts ansible.builtin.ping: - name: Print message ansible.builtin.debug: msg: Hello world ``` ```bash ansible-playbook -i inventory.ini playbook.yaml ``` -------------------------------- ### Ansible: Install Package with Policy RC_D Source: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module This example shows how to prevent a newly installed package from starting a service by setting a specific exit code for policy-rc.d. It uses the 'policy_rc_d' parameter. ```yaml --- - name: Install package without starting service apt: name: "package_name" policy_rc_d: 101 ``` -------------------------------- ### Installing Documentation Dependencies Source: https://docs.ansible.com/ansible/latest/community/documentation_contributions Installs project dependencies required for building Ansible documentation. It offers options to install either the tested (pinned) or unpinned dependency versions. ```bash pip install -r tests/requirements.in -c tests/requirements.txt # Installs tested dependency versions. pip install -r tests/requirements.in # Installs the unpinned dependency versions. ``` -------------------------------- ### Get BIOS Setup using inspur.ispim.bios_info Source: https://docs.ansible.com/ansible/latest/collections/inspur/ispim/bios_info_module An Ansible playbook example demonstrating how to use the inspur.ispim.bios_info module to retrieve BIOS setup information from an Inspur server. It configures connection details via a provider variable. ```yaml - name: Bios test hosts: ism connection: local gather_facts: no vars: ism: host: "{{ ansible_ssh_host }}" username: "{{ username }}" password: "{{ password }}" tasks: - name: "Get bios setup" inspur.ispim.bios_info: provider: "{{ ism }}" ``` -------------------------------- ### Run Ansible Playbook Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Execute an Ansible playbook to reconfigure the entire infrastructure. This command targets all hosts defined in the 'production' inventory file and runs the 'site.yml' playbook. ```ansible ansible-playbook -i production site.yml ``` -------------------------------- ### Debug LDAP Client Setup with Ansible Source: https://docs.ansible.com/ansible/latest/collections/microsoft/ad/docsite/guide_ldap_connection Uses the 'microsoft.ad.debug_ldap_client' action plugin to diagnose the Ansible host's LDAP setup and capabilities. This command helps identify installed Python packages, Kerberos information, and SRV lookup details. ```bash $ ansible localhost -m microsoft.ad.debug_ldap_client ``` -------------------------------- ### Ansible CLI Playbook Execution Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Shows command-line examples for executing Ansible playbooks. It includes running a main playbook (`site.yml`) and executing specific playbooks (`webservers.yml`) with or without limiting the scope to certain hosts. ```bash ansible-playbook site.yml --limit webservers ``` ```bash ansible-playbook webservers.yml ``` -------------------------------- ### Get VirtualHub Connection Info Source: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_virtualhubconnection_info_module Example of how to use the azure_rm_virtualhubconnection_info module in an Ansible playbook to retrieve information about Azure Virtual Hub connections. This module requires the azure.azcollection to be installed. ```ansible azure.azcollection.azure_rm_virtualhubconnection_info ``` -------------------------------- ### UTHelper.from_spec Example Source: https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_uthelper Demonstrates creating a UTHelper instance using a test specification dictionary. It requires the Ansible module, the test module, the test specification, and optionally a list of mocks. ```python import sys from ansible_collections.community.general.plugins.modules import ansible_module from .uthelper import UTHelper, RunCommandMock TEST_SPEC = dict( test_cases=[ ... ] ) helper = UTHelper.from_spec(ansible_module, sys.modules[__name__], TEST_SPEC, mocks=[RunCommandMock]) ``` -------------------------------- ### Install Composer Dependencies with Ansible Source: https://docs.ansible.com/ansible/latest/collections/community/general/composer_module This example demonstrates how to install all libraries and dependencies defined in a composer.lock file for a project. It specifies the command as 'install' and sets the working directory. ```ansible - name: Download and installs all libs and dependencies outlined in the /path/to/project/composer.lock community.general.composer: command: install working_dir: /path/to/project ``` -------------------------------- ### Get WAFv2 Web ACL Information Source: https://docs.ansible.com/ansible/latest/collections/community/aws/wafv2_resources_info_module This example demonstrates how to use the `community.aws.wafv2_resources_info` module to retrieve information about a specific Web ACL by its name and scope. It requires the `community.aws` collection to be installed. ```yaml - name: get web acl community.aws.wafv2_resources_info: name: string03 scope: REGIONAL ``` -------------------------------- ### Install hvac library Source: https://docs.ansible.com/ansible/latest/collections/community/hashi_vault/docsite/user_guide Installs the 'hvac' Python library, which is a requirement for the community.hashi_vault Ansible collection. ```shell $ pip install hvac ``` -------------------------------- ### Use azure.azcollection.azure_rm_keyvaultsecret_info module in playbook Source: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_keyvaultsecret_info_module Example of how to use the `azure_rm_keyvaultsecret_info` module within an Ansible playbook to get facts about an Azure Key Vault secret. This requires the `azure.azcollection` to be installed. ```yaml - name: Get Azure Key Vault secret facts azure.azcollection.azure_rm_keyvaultsecret_info: resource_group: myResourceGroup vault_name: myKeyVault secret_name: mySecret register: secret_facts - name: Display secret facts debug: var: secret_facts ``` -------------------------------- ### Download manual screenshots playbook example Source: https://docs.ansible.com/ansible/latest/collections/kaytus/ksmanage/download_manual_screenshot_module An Ansible playbook demonstrating how to use the `kaytus.ksmanage.download_manual_screenshot` module to download manual screenshots. It includes host configuration, variables for connection details, and the task to execute the module. ```yaml - name: Screen test hosts: ksmanage connection: local gather_facts: false vars: ksmanage: host: "{{ ansible_ssh_host }}" username: "{{ username }}" password: "{{ password }}" tasks: - name: "Download manual screenshots" kaytus.ksmanage.download_manual_screenshot: file_url: "/home/wbs/screen" provider: "{{ ksmanage }}" ``` -------------------------------- ### Install hvac Library Source: https://docs.ansible.com/ansible/latest/collections/community/hashi_vault/docsite/user_guide This command installs the necessary hvac Python library for the community.hashi_vault Ansible collection. ```APIDOC ## Install hvac Library ### Description Installs the required `hvac` Python library for the `community.hashi_vault` Ansible collection. ### Method ```bash ``` ### Endpoint ``` $ pip install hvac ``` ### Parameters ### Request Example ### Response ### Response Example ``` -------------------------------- ### Ansible CloudEngine OS Platform Options - NETCONF Source: https://docs.ansible.com/ansible/latest/network/user_guide/platform_ce Guides on enabling and using NETCONF connections with CloudEngine CE OS in Ansible, including prerequisites, inventory setup, and example tasks. ```APIDOC ## Ansible CloudEngine OS Platform Options - NETCONF ### Description This section details how to enable and utilize NETCONF connections for managing CloudEngine CE OS devices with Ansible. It covers the necessary prerequisites, how to configure your inventory for NETCONF access, and provides an example task for VLAN configuration. ### Method N/A (This is a configuration and usage guide) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example #### Prerequisites 1. Install the `ncclient` Python package: `pip install ncclient` 2. Enable NETCONF on the CloudEngine OS device(s). #### Enabling NETCONF via Ansible Task ```yaml - name: Enable NETCONF connection: ansible.netcommon.network_cli community.network.ce_config: lines: - snetconf server enable when: ansible_network_os == 'community.network.ce' ``` #### Inventory Example `[ce:vars]` ```ini [ce:vars] ansible_connection=ansible.netcommon.netconf ansible_network_os=community.network.ce ansible_user=myuser ansible_password=!vault | ansible_paramiko_proxy_command='-o ProxyCommand="ssh -W %h:%p -q bastion01"' ``` **Notes on Inventory:** - `ansible_password`: Can be omitted if using SSH keys or ssh-agent. - `ansible_paramiko_proxy_command`: Can be omitted if connecting directly, not via a bastion host. - SSH passwords cannot be provided via environment variables in `ProxyCommand`. ### Response #### Success Response (200) N/A (This section describes configuration and task execution) #### Response Example #### Task Example ```yaml - name: Create a vlan, id is 50(ce) community.network.ce_vlan: vlan_id: 50 name: WEB when: ansible_network_os == 'community.network.ce' ``` ``` -------------------------------- ### Install Prerequisites with DNF Source: https://docs.ansible.com/ansible/latest/getting_started_ee/setup_environment Installs essential packages for Ansible Execution Environments using the DNF package manager. Requires root privileges. ```shell sudo dnf install -y podman python3 python3-pip ``` -------------------------------- ### Installing Custom Ansible Collections Source: https://docs.ansible.com/ansible/latest/reference_appendices/glossary Provides an example of installing a custom Ansible collection identified by its namespace and collection name. This is a standard way to manage and distribute Ansible content. ```bash ansible-galaxy collection install ``` -------------------------------- ### Ansible Group and Host Variables Examples Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Provides examples of YAML files for defining Ansible group and host variables. These files are used to assign specific configurations and parameters to groups of hosts or individual hosts, facilitating environment-specific settings. ```yaml --- # file: group_vars/atlanta ntp: ntp-atlanta.example.com backup: backup-atlanta.example.com ``` ```yaml --- # file: group_vars/webservers apacheMaxRequestsPerChild: 3000 apacheMaxClients: 900 ``` ```yaml --- # file: group_vars/all ntp: ntp-boston.example.com backup: backup-boston.example.com ``` ```yaml --- # file: host_vars/db-bos-1.example.com foo_agent_port: 86 bar_agent_port: 99 ``` -------------------------------- ### Get Multiple Repository Script Facts with Details Source: https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_repository_script_facts_module Example playbook showing how to retrieve facts for multiple repository scripts with a 'standard' detail level, limiting results to 50 and starting from offset 0. ```yaml - name: show-repository-scripts cp_mgmt_repository_script_facts: details_level: standard limit: 50 offset: 0 ``` -------------------------------- ### List Ansible Playbook Tasks Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Preview the tasks that would be executed by an Ansible playbook without actually running them. This is useful for verifying the scope of playbook runs, especially when using tags or limits. ```ansible # confirm what task names would be run if I ran this command and said "just ntp tasks" ansible-playbook -i production webservers.yml --tags ntp --list-tasks ``` -------------------------------- ### Use azure.azcollection.azure_rm_batchaccountapplicationpackage_info Module Source: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_batchaccountapplicationpackage_info_module Example of how to use the `azure_rm_batchaccountapplicationpackage_info` module in an Ansible playbook to get Batch Account Application Package facts. This requires the `azure.azcollection` to be installed and necessary Python dependencies met. ```yaml --- - name: Get Azure Batch Account Application Package facts hosts: localhost tasks: - name: Retrieve Batch Account Application Package information azure.azcollection.azure_rm_batchaccountapplicationpackage_info: resource_group: myResourceGroup batch_account_name: myBatchAccount application_id: myApplication application_package_id: myApplicationPackage register: batch_app_package_info - name: Print Batch Account Application Package information debug: var: batch_app_package_info ``` -------------------------------- ### Ansible - Install multiple packages with ansible.builtin.package Source: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/package_module Example showing how to install multiple packages at once using a comma-separated string with the 'package' module. ```yaml tasks: - name: Install multiple packages ansible.builtin.package: name: "nginx,vim,wget" state: present ``` -------------------------------- ### Ansible Galaxy CLI: Installing Collections from Git Repositories Source: https://docs.ansible.com/ansible/latest/collections_guide/collections_installing Provides command-line examples for installing Ansible collections directly from Git repositories, including specifying branches, commits, or tags, and using different authentication methods. ```bash # Install a collection in a repository using the latest commit on the branch 'devel' ansible-galaxy collection install git+https://github.com/organization/repo_name.git,devel # Install a collection from a private GitHub repository ansible-galaxy collection install git@github.com:organization/repo_name.git # Install a collection from a local git repository ansible-galaxy collection install git+file:///home/user/path/to/repo_name.git ``` -------------------------------- ### Get all Dnac Packages using Ansible Source: https://docs.ansible.com/ansible/latest/collections/cisco/dnac/dnac_packages_info_module An Ansible playbook example demonstrating how to use the `cisco.dnac.dnac_packages_info` module to retrieve a list of all packages installed on Cisco DNA Center. It shows how to pass connection parameters and register the output. ```yaml --- - name: Get all Dnac Packages cisco.dnac.dnac_packages_info: dnac_host: "{{dnac_host}}" dnac_username: "{{dnac_username}}" dnac_password: "{{dnac_password}}" dnac_verify: "{{dnac_verify}}" dnac_port: "{{dnac_port}}" dnac_version: "{{dnac_version}}" dnac_debug: "{{dnac_debug}}" headers: "{{my_headers | from_json}}" register: result ``` -------------------------------- ### VM Hardware Configuration Example Source: https://docs.ansible.com/ansible/latest/collections/community/general/xenserver_guest_module This snippet demonstrates configuring the hardware for a VM, including the number of CPU cores and memory. ```YAML hardware: num_cpus: 2 num_cpu_cores_per_socket: 1 memory_mb: 2048 ``` -------------------------------- ### Get multiple exception group facts Source: https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_exception_group_facts_module An Ansible playbook example to retrieve facts for multiple exception groups, with detailed level set to 'standard', limiting results to 50, and starting from offset 0. ```yaml - name: show-exception-groups cp_mgmt_exception_group_facts: details_level: standard limit: 50 offset: 0 ``` -------------------------------- ### Setup Ansible Development Environment Source: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation Sets up the shell environment for running 'ansible-core' from a cloned repository. Supports Bash and Fish shells, with an option to suppress warnings. ```shell $ source ./hacking/env-setup ``` ```shell $ source ./hacking/env-setup.fish ``` ```shell $ source ./hacking/env-setup -q ``` -------------------------------- ### Setting up a Python Virtual Environment Source: https://docs.ansible.com/ansible/latest/community/documentation_contributions Creates and activates a Python virtual environment for installing project dependencies. This isolates project dependencies from the system's Python installation. ```bash python3 -m venv ./venv source ./venv/bin/activate ``` -------------------------------- ### Ansible VirtualBox Inventory Example Source: https://docs.ansible.com/ansible/latest/collections/community/general/virtualbox_inventory An example of configuring the `community.general.virtualbox` inventory plugin. It demonstrates setting the `settings_password_file`, defining a `query` for guest information, and using `compose` to set the `ansible_connection` based on the guest OS. ```yaml --- # file must be named vbox.yaml or vbox.yml plugin: community.general.virtualbox settings_password_file: /etc/virtualbox/secrets query: logged_in_users: /VirtualBox/GuestInfo/OS/LoggedInUsersList compose: ansible_connection: ('indows' in vbox_Guest_OS)|ternary('winrm', 'ssh') ``` -------------------------------- ### Use azure_rm_storageshare_info Module in Playbook Source: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_storageshare_info_module Example of how to use the azure.azcollection.azure_rm_storageshare_info module within an Ansible playbook to get facts about an Azure storage file share. This requires the azure.azcollection to be installed. ```yaml - name: Get Azure storage file share info azure.azcollection.azure_rm_storageshare_info: resource_group: myResourceGroup storage_account_name: mystorageaccount share_name: myshare register: share_info - debug: var: share_info ``` -------------------------------- ### Ansible Inventory Output Without dpapi-ng Library Source: https://docs.ansible.com/ansible/latest/collections/microsoft/ad/docsite/guide_ldap_inventory Example output from `ansible-inventory` when the `dpapi-ng` Python library is not installed. The `this_example` section includes a `debug` key indicating that decryption failed due to the missing library. ```yaml # ansible-inventory -i microsoft.ad.ldap.yml --host MYHOST --vars --yaml ansible_host: MYHOST.domain.com microsoft_ad_distinguished_name: CN=MYHOST,CN=Computers,DC=domain,DC=com raw_example: - toLZAWR7rgfk... this_example: debug: Cannot decrypt value as the Python library dpapi-ng is not installed encrypted_value: MIIETgYJKoZI... flags: 0 update_timestamp: 133281382308674404 ``` -------------------------------- ### Verify Ansible Environment Versions Source: https://docs.ansible.com/ansible/latest/getting_started_ee/setup_environment Checks the installed versions of ansible-navigator and ansible-builder to confirm successful installation. ```shell ansible-navigator --version ansible-builder --version ``` -------------------------------- ### Start NetApp ONTAP CIFS Server with Ansible Source: https://docs.ansible.com/ansible/latest/collections/netapp/ontap/na_ontap_cifs_server_module This example demonstrates how to start a CIFS server on NetApp ONTAP. The state is 'present' and the 'service_state' is set to 'started'. The example requires the CIFS server name, vserver, and connection details. ```yaml - name: Start cifs_server netapp.ontap.na_ontap_cifs_server: state: present name: data2 vserver: svm1 service_state: started hostname: "{{ netapp_hostname }}" username: "{{ netapp_username }}" password: "{{ netapp_password }}" ``` -------------------------------- ### Clone Ansible Repository Source: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation Clones the 'ansible-core' repository from GitHub to run it directly from source. ```shell $ git clone https://github.com/ansible/ansible.git $ cd ./ansible ``` -------------------------------- ### Install slackpkg package Source: https://docs.ansible.com/ansible/latest/collections/community/general/slackpkg_module This example demonstrates how to install a package named 'foo' using the slackpkg module in Ansible. It sets the desired state to 'present'. ```yaml - name: Install package foo community.general.slackpkg: name: foo state: present ``` -------------------------------- ### Get type of 'myvar' using type_debug filter Source: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/type_debug_filter This example demonstrates how to use the `type_debug` filter in Ansible to determine the data type of a variable named 'myvar'. It requires the `ansible-core` package, which is included in all Ansible installations. ```jinja2 {{ myvar | type_debug }} ``` -------------------------------- ### Execute Ad Hoc Ansible Commands Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Run ad hoc Ansible commands to perform simple tasks across specified hosts. Examples include pinging hosts and executing arbitrary commands on remote systems. ```ansible ansible boston -i production -m ping ansible boston -i production -m command -a '/sbin/reboot' ``` -------------------------------- ### Ansible Inventory Directory Structure Example Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup Illustrates an alternative Ansible inventory directory layout where each environment (production, staging) has its own dedicated directory containing hosts, group_vars, and host_vars. This promotes separation of variables between different environments. ```yaml inventories/ production/ hosts # inventory file for production servers group_vars/ group1.yml # here we assign variables to particular groups group2.yml host_vars/ hostname1.yml # here we assign variables to particular systems hostname2.yml staging/ hosts # inventory file for staging environment group_vars/ group1.yml # here we assign variables to particular groups group2.yml host_vars/ stagehost1.yml # here we assign variables to particular systems stagehost2.yml library/ module_utils/ filter_plugins/ site.yml webservers.yml dbservers.yml roles/ common/ webtier/ monitoring/ fooapp/ ``` -------------------------------- ### Get Multiple SMTP Server Facts with Pagination (Ansible) Source: https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_smtp_server_facts_module Shows how to retrieve multiple SMTP server facts with a 'standard' detail level, limiting the results to 50 and starting from offset 0. This example illustrates pagination and detail level control. ```yaml - name: show-smtp-servers cp_mgmt_smtp_server_facts: details_level: standard limit: 50 offset: 0 ``` -------------------------------- ### Get vmware.vmware_rest.appliance_services_info Module Example Source: https://docs.ansible.com/ansible/latest/collections/vmware/vmware_rest/appliance_services_info_module A playbook example demonstrating how to use the vmware.vmware_rest.appliance_services_info module to get information about the 'ntpd' service. It registers the result for further inspection. ```yaml - name: Get information about ntpd vmware.vmware_rest.appliance_services_info: service: ntpd register: result ``` -------------------------------- ### VM Disk Configuration Example Source: https://docs.ansible.com/ansible/latest/collections/community/general/xenserver_guest_module This snippet shows how to add a new disk to a VM, specifying its size in GB and the storage repository. ```YAML disks: - name: "New Disk" size_gb: 50 sr: "Local Storage" ``` -------------------------------- ### Retrieve all installed pipx applications Source: https://docs.ansible.com/ansible/latest/collections/community/general/pipx_info_module This example demonstrates how to retrieve information about all applications installed using pipx. It utilizes the community.general.pipx_info module with default parameters. ```yaml - name: retrieve all installed applications community.general.pipx_info: {} ``` -------------------------------- ### Ansible Directory Layout - Top Level Source: https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup This layout organizes Ansible tasks primarily within roles, using separate inventory files for different environments and top-level playbooks. It includes directories for inventory, group/host variables, custom modules, and playbooks. ```ansible production # inventory file for production servers staging # inventory file for staging environment group_vars/ group1.yml # here we assign variables to particular groups group2.yml host_vars/ hostname1.yml # here we assign variables to particular systems hostname2.yml library/ # if any custom modules, put them here (optional) module_utils/ # if any custom module_utils to support modules, put them here (optional) filter_plugins/ # if any custom filter plugins, put them here (optional) site.yml # main playbook webservers.yml # playbook for webserver tier dbservers.yml # playbook for dbserver tier tasks/ webservers-extra.yml # <-- avoids confusing playbook with task files ``` -------------------------------- ### Ansible: Install and Remove Overlay Packages Source: https://docs.ansible.com/ansible/latest/collections/community/general/rpm_ostree_pkg_module These examples demonstrate how to use the community.general.rpm_ostree_pkg module in Ansible playbooks to install and remove overlay packages. It shows basic installation, removal, and applying changes live, along with an example of handling potential transaction conflicts using retries and delays. ```yaml - name: Install overlay package community.general.rpm_ostree_pkg: name: nfs-utils state: present - name: Remove overlay package community.general.rpm_ostree_pkg: name: nfs-utils state: absent - name: Apply the overlay package live community.general.rpm_ostree_pkg: name: nfs-utils state: present apply_live: true # In case a different transaction is currently running the module would fail. # Adding a delay can help mitigate this problem: - name: Install overlay package community.general.rpm_ostree_pkg: name: nfs-utils state: present register: rpm_ostree_pkg until: rpm_ostree_pkg is not failed retries: 10 delay: 30 ``` -------------------------------- ### Install package foo using portinstall Source: https://docs.ansible.com/ansible/latest/collections/community/general/portinstall_module Example of using the portinstall module to install a package named 'foo' on a FreeBSD system. It sets the state to 'present'. ```yaml - name: Install package foo community.general.portinstall: name: foo state: present ``` -------------------------------- ### Create Ansible Project Directory Source: https://docs.ansible.com/ansible/latest/getting_started/get_started_ansible Creates a new directory for your Ansible automation project and navigates into it. This is the first step in organizing your Ansible content. ```bash mkdir ansible_quickstart && cd ansible_quickstart ``` -------------------------------- ### Get multiple resource-ftp object facts with filtering Source: https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_resource_ftp_facts_module This example shows how to retrieve multiple resource-ftp objects facts, with a 'standard' detail level, limiting results to 50 and starting from offset 0. It also includes filtering capabilities. ```ansible - name: show-resources-ftp cp_mgmt_resource_ftp_facts: details_level: standard limit: 50 offset: 0 ``` -------------------------------- ### vultr.cloud.startup_script_info Module Source: https://docs.ansible.com/ansible/latest/collections/vultr/cloud/startup_script_info_module Gather information about startup scripts available from Vultr. ```APIDOC ## POST /vultr.cloud.startup_script_info ### Description Gather information about startup scripts available from Vultr. ### Method POST ### Endpoint vultr.cloud.startup_script_info ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **api_endpoint** (string) - Optional - URL to API endpint (without trailing slash). Fallback environment variable `VULTR_API_ENDPOINT`. Default: "https://api.vultr.com/v2" - **api_key** (string) - Required - API key of the Vultr API. Fallback environment variable `VULTR_API_KEY`. - **api_retries** (integer) - Optional - Amount of retries in case of the Vultr API retuns an HTTP error code. Fallback environment variable `VULTR_API_RETRIES`. Default: 5 - **api_retry_max_delay** (integer) - Optional - Retry backoff delay in seconds is exponential up to this max. value. Fallback environment variable `VULTR_API_RETRY_MAX_DELAY`. Default: 12 - **api_timeout** (integer) - Optional - HTTP timeout to Vultr API. Fallback environment variable `VULTR_API_TIMEOUT`. Default: 180 - **validate_certs** (boolean) - Optional - Validate SSL certs of the Vultr API. Choices: `false`, `true`. Default: `true` ### Request Example ```json { "api_key": "YOUR_API_KEY" } ``` ### Response #### Success Response (200) - **vultr_api** (dictionary) - Response from Vultr API with a few additions/modification. - **api_endpoint** (string) - Endpoint used for the API requests. Sample: "https://api.vultr.com/v2" - **api_retries** (integer) - Amount of max retries for the API requests. Sample: 5 - **api_retry_max_delay** (integer) - Exponential backoff delay in seconds between retries up to this max delay value. Sample: 12 - **api_timeout** (integer) - Timeout used for the API requests. Sample: 60 - **vultr_startup_script_info** (list) - Response from Vultr API. elements=string - **date_created** (string) - Date the startup script was created. Sample: "2020-10-10T01:56:20+00:00" - **date_modified** (string) - Date the startup script was modified. Sample: "2020-10-10T01:56:20+00:00" - **id** (string) - ID of the startup script. Sample: "56e5b8b5-120c-40b1-a087-3abc9cd8df57" - **name** (string) - Name of the startup script. Sample: "my startup script" - **type** (string) - The type of the startup script. Sample: "pxe" #### Response Example ```json { "vultr_api": {}, "api_endpoint": "https://api.vultr.com/v2", "api_retries": 5, "api_retry_max_delay": 12, "api_timeout": 60, "vultr_startup_script_info": [ { "date_created": "2020-10-10T01:56:20+00:00", "date_modified": "2020-10-10T01:56:20+00:00", "id": "56e5b8b5-120c-40b1-a087-3abc9cd8df57", "name": "my startup script", "type": "pxe" } ] } ``` ``` -------------------------------- ### Use azure_rm_virtualmachinescalesetextension_info in Ansible Playbook Source: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_virtualmachinescalesetextension_info_module This is an example of how to use the `azure_rm_virtualmachinescalesetextension_info` module within an Ansible playbook to get facts about an Azure Virtual Machine Scale Set Extension. It requires the `azure.azcollection` to be installed. ```yaml - name: Get Azure VM Scale Set Extension facts hosts: localhost tasks: - name: Retrieve extension information azure.azcollection.azure_rm_virtualmachinescalesetextension_info: resource_group: "myResourceGroup" virtual_machine_scale_set_name: "myVmss" name: "myExtensionName" register: extension_info - name: Print extension facts debug: var: extension_info ``` -------------------------------- ### Get multiple service-tcp facts with Ansible Source: https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_service_tcp_facts_module An Ansible playbook example showing how to use the `cp_mgmt_service_tcp_facts` module to retrieve a limited set of service-tcp objects (up to 10, starting from offset 0) with standard detail level. This utilizes the `details_level`, `limit`, and `offset` parameters. ```ansible - name: show-services-tcp cp_mgmt_service_tcp_facts: details_level: standard limit: 10 offset: 0 ``` -------------------------------- ### Install Unit Test Dependencies Source: https://docs.ansible.com/ansible/latest/dev_guide/testing_units Example of installing necessary dependencies for running unit tests using the `--requirements` option. This is an alternative to using `--docker` or `--venv`. ```bash ansible-test units --python 2.7 --requirements apache2_module ``` -------------------------------- ### UTHelper.from_file Example Source: https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_uthelper Shows how to instantiate UTHelper from a YAML test specification file. This method requires a file handle to the YAML file. ```python import sys from ansible_collections.community.general.plugins.modules import ansible_module from .uthelper import UTHelper, RunCommandMock with open("test_spec.yaml", "r") as test_spec_filehandle: helper = UTHelper.from_file(ansible_module, sys.modules[__name__], test_spec_filehandle, mocks=[RunCommandMock]) ``` -------------------------------- ### Ansible playbooks for gunicorn configuration Source: https://docs.ansible.com/ansible/latest/collections/community/general/gunicorn_module Examples of Ansible playbooks demonstrating how to use the community.general.gunicorn module to start gunicorn with different configurations, including basic runs, virtual environment usage, and specifying configuration files. ```yaml - name: Simple gunicorn run example community.general.gunicorn: app: 'wsgi' chdir: '/workspace/example' - name: Run gunicorn on a virtualenv community.general.gunicorn: app: 'wsgi' chdir: '/workspace/example' venv: '/workspace/example/venv' - name: Run gunicorn with a config file community.general.gunicorn: app: 'wsgi' chdir: '/workspace/example' conf: '/workspace/example/gunicorn.cfg' - name: Run gunicorn as ansible user with specified pid and config file community.general.gunicorn: app: 'wsgi' chdir: '/workspace/example' conf: '/workspace/example/gunicorn.cfg' venv: '/workspace/example/venv' pid: '/workspace/example/gunicorn.pid' user: 'ansible' ``` -------------------------------- ### Ansible Inventory Output with Decryption Authorization Error Source: https://docs.ansible.com/ansible/latest/collections/microsoft/ad/docsite/guide_ldap_inventory Example output from `ansible-inventory` when the `dpapi-ng` library is installed but the connection user lacks authorization to decrypt the LAPS value. The `this_example` section shows a `debug` key with an error message related to key retrieval. ```yaml # ansible-inventory -i microsoft.ad.ldap.yml --host MYHOST --vars --yaml ansible_host: MYHOST.domain.com microsoft_ad_distinguished_name: CN=MYHOST,CN=Computers,DC=domain,DC=com raw_example: - toLZAWR7rgfk... this_example: debug: Failed to decrypt value due to error - ValueError GetKey failed 0x80070005 encrypted_value: MIIETgYJKoZI... flags: 0 update_timestamp: 133281382308674404 ``` -------------------------------- ### Basic Fedora VM Creation with Ansible Source: https://docs.ansible.com/ansible/latest/collections/community/libvirt/virt_install_module This example demonstrates how to create a basic Fedora virtual machine using the virt_install module. It specifies the VM name, memory, vCPUs, disk size, OS information, installation location, and graphics type. ```yaml - name: Create a basic Fedora VM community.libvirt.virt_install: name: my-fedora-vm memory: 2048 vcpus: 2 disks: - size: 20 osinfo: name: fedora39 location: https://download.fedoraproject.org/pub/fedora/linux/releases/39/Server/x86_64/ graphics: type: spice networks: - network: default ``` -------------------------------- ### Get Azure SQL Firewall Rule Facts using Ansible Source: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_sqlfirewallrule_info_module Example of how to use the azure.azcollection.azure_rm_sqlfirewallrule_info module in an Ansible playbook to retrieve facts about Azure SQL Firewall Rules. Ensure the azure.azcollection is installed and its Python dependencies are met. ```ansible - name: Get Azure SQL Firewall Rule facts azure.azcollection.azure_rm_sqlfirewallrule_info: resource_group: myResourceGroup server_name: myServer firewall_rule_name: myFirewallRule register: firewall_rule_info - name: Display firewall rule information debug: var: firewall_rule_info ``` -------------------------------- ### Basic Fact Gathering and Filtering Source: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module Provides examples of basic Ansible commands to gather and filter system facts. These commands are useful for quickly retrieving specific information from all hosts. ```ansible # Display only facts regarding memory found by ansible on all hosts and output them. # ansible all -m ansible.builtin.setup -a 'filter=ansible_*_mb' # Display only facts returned by facter. # ansible all -m ansible.builtin.setup -a 'filter=facter_*' # Collect only facts returned by facter. # ansible all -m ansible.builtin.setup -a 'gather_subset=!all,facter' # Display only facts about certain interfaces. # ansible all -m ansible.builtin.setup -a 'filter=ansible_eth[0-2]' ```