### Install Python Dependencies Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Install the necessary Python libraries for the plugin to function. Ensure you are using a compatible Python version. ```bash pip install aiounifi aiohttp PyYAML ``` -------------------------------- ### Install Ansible Collection from Git Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Install the collection directly from the GitHub repository using the Ansible Galaxy CLI. ```bash ansible-galaxy collection install git+https://github.com/aioue/ansible-unifi-inventory.git ``` -------------------------------- ### Configure Inventory for Multiple Sites Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Create separate inventory files for each site in a multi-site UniFi controller setup. Specify the site name using the `site` parameter. ```yaml plugin: aioue.network.unifi url: "https://192.168.1.1" token: "your-token" site: "default" ``` ```yaml plugin: aioue.network.unifi url: "https://192.168.1.1" token: "your-token" site: "branch-office" ``` -------------------------------- ### Ansible Collection Requirements File Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Define the collection in a requirements.yml file for automated installation with Ansible Galaxy. ```yaml --- collections: - name: aioue.network source: https://github.com/aioue/ansible-unifi-inventory.git type: git # If you need a specific version, you can specify a branch or tag: # version: main ``` -------------------------------- ### UniFi Inventory Configuration Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Configure the plugin in a YAML inventory file. Ensure the FQCN is used and provide controller connection details and authentication credentials. ```yaml # Example: unifi_inventory.yml # Use the FQCN for the plugin plugin: aioue.network.unifi # UniFi controller URL (required) url: "https://192.168.1.1" # --- Authentication --- # Provide EITHER token OR username/password # API Token (Preferred method) # Leave empty to use username/password token: "your-api-token-here" # Username/Password (Alternative) # Must be a LOCAL admin account without 2FA username: "ansible-admin" password: "your-password" # --------------------- # UniFi site name site: "default" # Set to false for self-signed certificates verify_ssl: false # Set to true to include APs, switches, etc. include_devices: false # Only include clients seen in the last 30 minutes last_seen_minutes: 30 # Cache API results for 30 seconds cache_ttl: 30 ``` -------------------------------- ### View Inventory Graph Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Use this command to visualize the discovered hosts and their groupings from the UniFi controller. ```shell $ ansible-inventory -i inventory/unifi.yaml all --graph ``` -------------------------------- ### List All Inventory Hosts Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Fetch and display the complete inventory of discovered hosts from the UniFi controller in JSON format. ```bash ansible-inventory -i unifi_inventory.yml --list ``` -------------------------------- ### Run Command on Wireless Clients Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Execute an ad-hoc command, like 'uptime', specifically on hosts identified as wireless clients by the plugin. ```bash ansible -i unifi_inventory.yml unifi_wireless_clients -m shell -a "uptime" ``` -------------------------------- ### Tag and Push Release Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Tag a new version and push it to the origin repository to trigger the automated release process. Ensure the tag format is correct (e.g., v1.x.x). ```bash git tag v1.x.x git push origin v1.x.x ``` -------------------------------- ### Include Infrastructure Devices Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Enable this option to add network infrastructure devices like APs, switches, and gateways to your inventory. Requires correct plugin and token configuration. ```yaml plugin: aioue.network.unifi url: "https://192.168.1.1" token: "your-token" include_devices: true ``` -------------------------------- ### Merge Multiple Inventory Sources Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Combine the UniFi dynamic inventory with a static inventory file for a comprehensive Ansible execution. ```bash ansible-playbook -i static_hosts.yml -i unifi_inventory.yml site.yml ``` -------------------------------- ### Filter by Last Seen Time Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Use this configuration to include only clients seen within a specified number of minutes. Ensure the plugin and URL are correctly set. ```yaml plugin: aioue.network.unifi url: "https://192.168.1.1" token: "your-token" last_seen_minutes: 5 ``` -------------------------------- ### Ping All Discovered Hosts Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Perform a basic connectivity check (ping) against all hosts discovered by the UniFi inventory plugin. ```bash ansible -i unifi_inventory.yml all -m ping ``` -------------------------------- ### Environment Variables for Configuration Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Override inventory file settings by exporting configuration parameters as environment variables. This is useful for CI/CD pipelines or sensitive information. ```bash export UNIFI_URL=https://192.168.1.1 export UNIFI_TOKEN=your-api-token-here export UNIFI_SITE=default export UNIFI_VERIFY_SSL=false ``` -------------------------------- ### Run Playbook Against UniFi Inventory Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Execute an Ansible playbook using the UniFi dynamic inventory. This allows you to manage devices discovered from your UniFi controller. ```bash ansible-playbook -i unifi_inventory.yml site.yml ``` -------------------------------- ### Show Hosts in a Specific Group Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Filter and display hosts belonging to a particular dynamic group, such as 'unifi_wired_clients'. ```bash ansible-inventory -i unifi_inventory.yml --graph unifi_wired_clients ``` -------------------------------- ### Run Command on Specific SSID Group Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Target hosts associated with a particular Wi-Fi network (SSID) and execute a command on them. ```bash ansible -i unifi_inventory.yml ssid_guest_wifi -m shell -a "uptime" ``` -------------------------------- ### Use Environment Variables for Secrets Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Inject secrets like controller URL and API token using environment variables. This is suitable for CI/CD pipelines. ```bash export UNIFI_URL=https://192.168.1.1 export UNIFI_TOKEN=$VAULT_UNIFI_TOKEN ``` ```bash ansible-playbook -i unifi_inventory.yml site.yml ``` -------------------------------- ### Encrypt and Use Ansible Vault Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Encrypt your sensitive inventory file using Ansible Vault. This is recommended for securely storing credentials. ```bash ansible-vault encrypt unifi_inventory.yml ``` ```bash ansible-playbook -i unifi_inventory.yml site.yml --ask-vault-pass ``` -------------------------------- ### Limit Playbook to Dynamic Group Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Run an Ansible playbook but restrict its execution to a specific dynamic group of hosts, such as 'unifi_clients'. ```bash ansible-playbook -i unifi_inventory.yml site.yml --limit unifi_clients ``` -------------------------------- ### Disable Caching Source: https://github.com/aioue/ansible-unifi-inventory/blob/main/README.md Set `cache_ttl` to 0 to disable inventory caching for real-time data. Be aware this will increase API load and slow down inventory runs. ```yaml plugin: aioue.network.unifi url: "https://192.168.1.1" token: "your-token" cache_ttl: 0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.