### Install Flatpak App from Flatpakref File Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Installs a Flatpak application directly from its .flatpakref file. This is useful for installing applications without adding their repository first. ```bash flatpak --system install --from /tmp/flatpak/repo/com.dummy.App$NUM.flatpakref ``` -------------------------------- ### Install Flatpak App from Local Repository Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Installs a Flatpak application from the previously added local repository. Replace NUM with the appropriate number for the desired application. ```bash flatpak --system install dummy-repo com.dummy.App$NUM ``` -------------------------------- ### Install Flatpak Runtimes Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Installs the necessary system-wide Flatpak runtimes and SDKs required for building and running Flatpak applications. Ensure 'flathub' is already configured as a remote. ```bash flatpak install --system flathub org.freedesktop.Platform//1.6 org.freedesktop.Sdk//1.6 ``` -------------------------------- ### Replace Keys Using 'starts_with' Matching Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst This example demonstrates replacing keys that start with a specified string. The 'matching_parameter' is set to 'starts_with', and the 'before' attribute defines the prefix to match. ```yaml result: - a0: A0 a1: B0 k2_x2: - C0 k3_x3: foo - a0: A1 a1: B1 k2_x2: - C1 k3_x3: bar ``` ```yaml+jinja mp: starts_with target: - {after: a0, before: k0} - {after: a1, before: k1} result: "{{ input | community.general.replace_keys(target=target, matching_parameter=mp) }}" ``` -------------------------------- ### YAML Test Case Structure Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_uthelper.rst This YAML defines a test case for installing a package using opkg, including input parameters, expected output, and mocked run_command interactions with environment settings and return codes. ```yaml --- anchors: environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} test_cases: - id: install_zlibdev input: name: zlib-dev state: present output: msg: installed 1 package(s) mocks: run_command: - command: [/testbin/opkg, --version] environ: *env-def rc: 0 out: '' err: '' - command: [/testbin/opkg, list-installed, zlib-dev] environ: *env-def rc: 0 out: '' err: '' - command: [/testbin/opkg, install, zlib-dev] environ: *env-def rc: 0 out: | Installing zlib-dev (1.2.11-6) to root... Downloading https://downloads.openwrt.org/releases/22.03.0/packages/mips_24kc/base/zlib-dev_1.2.11-6_mips_24kc.ipk Installing zlib (1.2.11-6) to root... Downloading https://downloads.openwrt.org/releases/22.03.0/packages/mips_24kc/base/zlib_1.2.11-6_mips_24kc.ipk Configuring zlib. Configuring zlib-dev. err: '' - command: [/testbin/opkg, list-installed, zlib-dev] environ: *env-def rc: 0 out: | zlib-dev - 1.2.11-6 err: '' - id: install_zlibdev_present input: name: zlib-dev state: present output: msg: package(s) already present mocks: run_command: - command: [/testbin/opkg, --version] environ: *env-def rc: 0 out: '' err: '' - command: [/testbin/opkg, list-installed, zlib-dev] environ: *env-def rc: 0 out: | zlib-dev - 1.2.11-6 err: '' ``` -------------------------------- ### Start Keycloak Server with Docker/Podman Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_realm_users_info/README.md Starts a Keycloak server instance using Docker or Podman for integration testing. Ensure the KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD environment variables are set. ```bash podman|docker run -d --rm --name mykeycloak -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password quay.io/keycloak/keycloak:latest start-dev --http-relative-path /auth ``` -------------------------------- ### Start and Run Keycloak Client Secret Info Integration Test Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_clientsecret_info/README.md Use these commands to start the necessary Docker containers and then execute the integration test. ```bash # 1. Start docker-compose: docker-compose -f tests/integration/targets/keycloak_clientsecret_info/docker-compose.yml stop docker-compose -f tests/integration/targets/keycloak_clientsecret_info/docker-compose.yml rm -f -v docker-compose -f tests/integration/targets/keycloak_clientsecret_info/docker-compose.yml up -d # 2. Run the integration tests: ansible-test integration keycloak_clientsecret_info --allow-unsupported -v ``` -------------------------------- ### Start All Jails Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_aliases.rst Start all jails that have been created. This command initiates the jails and configures their network interfaces. ```console shell> iocage start ALL No default gateway found for ipv6. * Starting 052b9557 + Started OK + Using devfs_ruleset: 1000 (iocage generated default) + Configuring VNET OK + Using IP options: vnet + Starting services OK + Executing poststart OK + DHCP Address: 10.1.0.137/24 No default gateway found for ipv6. * Starting 1c11de2d + Started OK + Using devfs_ruleset: 1001 (iocage generated default) + Configuring VNET OK + Using IP options: vnet + Starting services OK + Executing poststart OK + DHCP Address: 10.1.0.146/24 No default gateway found for ipv6. * Starting 9d94cc9e + Started OK + Using devfs_ruleset: 1002 (iocage generated default) + Configuring VNET OK + Using IP options: vnet + Starting services OK + Executing poststart OK + DHCP Address: 10.1.0.115/24 Please convert back to a jail before trying to start ansible_client ``` -------------------------------- ### Start all iocage jails Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_dhcp.rst Execute this command on the iocage host to start all configured jails. It displays the status of each jail and the DHCP-assigned IP address if successful. ```console shell> iocage start ALL No default gateway found for ipv6. * Starting srv_1 + Started OK + Using devfs_ruleset: 1000 (iocage generated default) + Configuring VNET OK + Using IP options: vnet + Starting services OK + Executing poststart OK + DHCP Address: 10.1.0.183/24 No default gateway found for ipv6. * Starting srv_2 + Started OK + Using devfs_ruleset: 1001 (iocage generated default) + Configuring VNET OK + Using IP options: vnet + Starting services OK + Executing poststart OK + DHCP Address: 10.1.0.204/24 No default gateway found for ipv6. * Starting srv_3 + Started OK + Using devfs_ruleset: 1002 (iocage generated default) + Configuring VNET OK + Using IP options: vnet + Starting services OK + Executing poststart OK + DHCP Address: 10.1.0.169/24 Please convert back to a jail before trying to start ansible_client ``` -------------------------------- ### Start Keycloak Server with Docker Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_realm/README.md Starts a Keycloak server instance using Docker for integration testing. Ensure Keycloak is accessible on port 8080. ```bash docker run -d --rm --name mykeycloak -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password quay.io/keycloak/keycloak:latest start-dev --http-relative-path /auth ``` -------------------------------- ### Start Docker Compose and Run Integration Tests Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_clientscope_type/README.md Use these commands to start the necessary Docker containers and then execute the integration tests for the Keycloak client scope type. ```bash # 1. Start docker-compose: docker-compose -f tests/integration/targets/keycloak_clientscope_type/docker-compose.yml down docker-compose -f tests/integration/targets/keycloak_clientscope_type/docker-compose.yml up -d # 2. Run the integration tests: ansible-test integration keycloak_clientscope_type --allow-unsupported -v ``` -------------------------------- ### Generated Command Line Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_cmdrunner.rst Illustrates the structure of a command line generated by CmdRunner, showing how arguments are formatted and included. ```text [ "/bin/ansible-galaxy", "collection", "install", "--upgrade", "-p", "", "netbox.netbox", ] ``` -------------------------------- ### Module Initialization and Execution Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_modulehelper.rst Demonstrates the basic structure of a module using ModuleHelper, including initialization, running logic, and handling failures via exceptions. ```python def __init_module__(self): self.vars.original_message = '' self.vars.message = '' def __run__(self): if self.check_mode: return self.vars.original_message = self.vars.name self.vars.message = 'goodbye' self.changed = self.vars['new'] def __quit_module__(self): if self.vars.name == "fail me": self.do_raise("You requested this to fail") ``` -------------------------------- ### Example Output of iocage Properties Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_properties.rst This is an example of the output you can expect when the playbook successfully retrieves and displays the iocage properties for a host. It shows various configuration details of the iocage jail. ```text PLAY [all] ********************************************************************************************************** TASK [debug] ********************************************************************************************************** ok: [srv_3] => iocage_properties: CONFIG_VERSION: '33' allow_chflags: '0' allow_mlock: '0' allow_mount: '1' allow_mount_devfs: '0' allow_mount_fdescfs: '0' allow_mount_fusefs: '0' allow_mount_linprocfs: '0' allow_mount_linsysfs: '0' allow_mount_nullfs: '0' allow_mount_procfs: '0' allow_mount_tmpfs: '0' allow_mount_zfs: '0' allow_nfsd: '0' allow_quotas: '0' allow_raw_sockets: '0' allow_set_hostname: '1' allow_socket_af: '0' allow_sysvipc: '0' allow_tun: '0' allow_vmm: '0' assign_localhost: '0' available: readonly basejail: '0' boot: '0' bpf: '1' children_max: '0' cloned_release: 14.2-RELEASE comment: none compression: 'on' compressratio: readonly coredumpsize: 'off' count: '1' cpuset: 'off' cputime: 'off' datasize: 'off' dedup: 'off' defaultrouter: auto defaultrouter6: auto depends: none devfs_ruleset: '4' dhcp: '1' enforce_statfs: '2' exec_clean: '1' exec_created: /usr/bin/true exec_fib: '0' exec_jail_user: root exec_poststart: /usr/bin/true exec_poststop: /usr/bin/true exec_prestart: /usr/bin/true exec_prestop: /usr/bin/true exec_start: /bin/sh /etc/rc exec_stop: /bin/sh /etc/rc.shutdown exec_system_jail_user: '0' exec_system_user: root exec_timeout: '60' host_domainname: none host_hostname: srv-3 host_hostuuid: srv_3 host_time: '1' hostid: ea2ba7d1-4fcd-f13f-82e4-8b32c0a03403 hostid_strict_check: '0' interfaces: vnet0:bridge0 ip4: new ip4_addr: none ip4_saddrsel: '1' ip6: new ip6_addr: none ip6_saddrsel: '1' ip_hostname: '0' jail_zfs: '0' jail_zfs_dataset: iocage/jails/srv_3/data jail_zfs_mountpoint: none last_started: '2025-06-11 04:29:23' localhost_ip: none login_flags: -f root mac_prefix: 02a098 maxproc: 'off' memorylocked: 'off' memoryuse: 'off' min_dyn_devfs_ruleset: '1000' mount_devfs: '1' mount_fdescfs: '1' mount_linprocfs: '0' mount_procfs: '0' mountpoint: readonly msgqqueued: 'off' msgqsize: 'off' nat: '0' nat_backend: ipfw nat_forwards: none nat_interface: none nat_prefix: '172.16' nmsgq: 'off' notes: none nsem: 'off' nsemop: 'off' nshm: 'off' nthr: 'off' openfiles: 'off' origin: readonly owner: root pcpu: 'off' plugin_name: none plugin_repository: none priority: '99' pseudoterminals: 'off' quota: none readbps: 'off' readiops: 'off' release: 14.2-RELEASE-p3 reservation: none resolver: /etc/resolv.conf rlimits: 'off' rtsold: '0' ``` -------------------------------- ### Install Specific Version of Community.general Collection Source: https://github.com/ansible-collections/community.general/blob/main/README.md Installs a specific version of the community.general collection. Use this command when you need a particular version, for example, to avoid issues with a recent release or for compatibility testing. ```bash ansible-galaxy collection install community.general:==X.Y.Z ``` -------------------------------- ### Start Docker Compose and Run Integration Tests Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/jenkins_credential/README.md Use these commands to start the necessary Docker containers and then run the integration tests for the Jenkins credential module. ```bash # 1. Start docker-compose: docker-compose -f tests/integration/targets/jenkins_credential/docker-compose.yml down docker-compose -f tests/integration/targets/jenkins_credential/docker-compose.yml up -d ``` ```bash # 2. Run the integration tests: ansible-test integration jenkins_credential --allow-unsupported -v ``` -------------------------------- ### Install Flatpak App Without Dependencies Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Installs a Flatpak application from the local repository, intentionally skipping any runtime dependencies. This is useful for testing installation logic rather than application functionality. ```bash flatpak --system install --no-deps dummy-repo com.dummy.App$NUM ``` -------------------------------- ### Run Keycloak Server for Tests Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_authz_permission/readme.adoc Use this command to start a Keycloak server instance for integration tests. Ensure to replace placeholder values with your specific configuration. ```bash docker run --name mykeycloak -p 8080:8080 -e KC_HTTP_RELATIVE_PATH= -e KEYCLOAK_ADMIN= -e KEYCLOAK_ADMIN_PASSWORD= quay.io/keycloak/keycloak:20.0.2 start-dev ``` ```bash docker run --name mykeycloak -p 8080:8080 -e KC_HTTP_RELATIVE_PATH=/auth -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password quay.io/keycloak/keycloak:20.0.2 start-dev ``` -------------------------------- ### Source Ansible Environment Setup Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_realm_users_info/README.md Sources the Ansible environment setup script from the Ansible GitHub repository. This is a prerequisite for running Ansible integration tests. ```bash Source Ansible env-setup from ansible github repository ``` -------------------------------- ### Start and Run Keycloak Client Secret Regenerate Integration Test Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_clientsecret_regenerate/README.md Use these commands to stop, remove, and start the docker-compose environment, then execute the integration test. Ensure the docker-compose file is in the correct directory. ```bash # 1. Start docker-compose: docker-compose -f tests/integration/targets/keycloak_clientsecret_regenerate/docker-compose.yml stop docker-compose -f tests/integration/targets/keycloak_clientsecret_regenerate/docker-compose.yml rm -f -v docker-compose -f tests/integration/targets/keycloak_clientsecret_regenerate/docker-compose.yml up -d # 2. Run the integration tests: ansible-test integration keycloak_clientsecret_regenerate --allow-unsupported -v ``` -------------------------------- ### Extract ports from servers with names starting with 'server1' Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide_selecting_json_data.rst This example filters servers whose names begin with 'server1' and extracts their port numbers. It utilizes the `starts_with` function within the JMESPath query. ```yaml - name: Display all ports from cluster1 ansible.builtin.debug: msg: "{{ domain_definition | to_json | from_json | community.general.json_query(server_name_query) }}" vars: server_name_query: "domain.server[?starts_with(name,'server1')].port" ``` -------------------------------- ### Define Lists for Examples Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst These lists are used in subsequent examples to demonstrate the functionality of the list filters. ```yaml A: [9, 5, 7, 1, 9, 4, 10, 5, 9, 7] B: [4, 1, 2, 8, 3, 1, 7] C: [10, 2, 1, 9, 1] ``` -------------------------------- ### Run Keycloak Docker Container Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_authz_authorization_scope/readme.adoc Use this command to start a Keycloak server instance for testing. Replace ``, ``, and `` with your desired values. ```bash docker run --name mykeycloak -p 8080:8080 -e KC_HTTP_RELATIVE_PATH= -e KEYCLOAK_ADMIN= -e KEYCLOAK_ADMIN_PASSWORD= quay.io/keycloak/keycloak:20.0.2 start-dev ``` -------------------------------- ### Virtual Environment Command Line Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_cmdrunner.rst Shows the command line generated when the 'venv' parameter is used to specify a Python virtual environment. ```shell /work/venv/bin/python -m django ... ``` -------------------------------- ### Install Community.general Collection via requirements.yml Source: https://github.com/ansible-collections/community.general/blob/main/README.md Installs the community.general collection by referencing it in a requirements.yml file. This is useful for managing collection dependencies in a reproducible way. ```yaml collections: - name: community.general ``` -------------------------------- ### Install ansible-builder Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_ee.rst Install the `ansible-builder` tool using pip. This tool is used for creating custom Execution Environments. ```shell $ pip install ansible-builder ``` -------------------------------- ### Start Keycloak Server with Docker Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_component_info/README.md Starts a Keycloak server instance in detached mode, linking it to a local LDAP server and exposing the necessary ports. It also sets up administrative credentials. ```bash docker run -d --rm --name myldap -p 389:389 minkwe/389ds:latest docker run -d --rm --name mykeycloak --link myldap:ldap.example.com -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password quay.io/keycloak/keycloak:latest start-dev --http-relative-path /auth ``` -------------------------------- ### Start Docker Container in Integration Test Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_docker/README.md Use the community.docker.docker_container module in your tasks/main.yml to start a Docker container for your integration test. Ensure ports are published and consider using wait_for for service availability. ```yaml - name: Start container community.docker.docker_container: name: mssql-test image: "mcr.microsoft.com/mssql/server:2019-latest" env: ACCEPT_EULA: "Y" SA_PASSWORD: "{{ mssql_login_password }}" MSSQL_PID: Developer ports: - "{{ mssql_port }}:1433" detach: true auto_remove: true memory: 2200M ``` -------------------------------- ### Install Community.general Collection Source: https://github.com/ansible-collections/community.general/blob/main/README.md Installs the community.general collection from Ansible Galaxy. This is the primary command for obtaining the collection if it's not included with your Ansible package. ```bash ansible-galaxy collection install community.general ``` -------------------------------- ### Start Keycloak Development Server Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_group_rolemapping/README.md Launches a Keycloak development server using Docker. Ensure Keycloak versions 22.0 or 23.0 are used for compatibility. ```sh docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password --rm quay.io/keycloak/keycloak:22.0 start-dev ``` -------------------------------- ### Scaleway Inventory Output Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_scaleway.rst Example JSON output from the `ansible-inventory --list` command using the Scaleway dynamic inventory plugin. It shows host variables and group memberships based on region and tags. ```json { "_meta": { "hostvars": { "dd8e3ae9-0c7c-459e-bc7b-aba8bfa1bb8d": { "ansible_verbosity": 6, "arch": "x86_64", "commercial_type": "START1-S", "hostname": "foobar", "ipv4": "192.0.2.1", "organization": "00000000-1111-2222-3333-444444444444", "state": "running", "tags": [ "web_server" ] } } }, "all": { "children": [ "ams1", "par1", "ungrouped", "web_server" ] }, "ams1": {}, "par1": { "hosts": [ "dd8e3ae9-0c7c-459e-bc7b-aba8bfa1bb8d" ] }, "ungrouped": {}, "web_server": { "hosts": [ "dd8e3ae9-0c7c-459e-bc7b-aba8bfa1bb8d" ] } } ``` -------------------------------- ### Install Internal Test Tools Source: https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md Clone the community.internal_test_tools repository to satisfy dependencies for running unit tests. ```bash git clone https://github.com/ansible-collections/community.internal_test_tools.git ~/dev/ansible_collections/community/internal_test_tools ``` -------------------------------- ### Create List of Dictionaries with map, reverse, and community.general.dict Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide_abstract_informations_dictionaries.rst This example demonstrates a complex transformation using `map` and `community.general.dict` to create a list of dictionaries. It involves zipping values with keys, reversing pairs, and then converting each processed pair into a dictionary. ```yaml+jinja - name: Create a list of dictionaries with map and the community.general.dict filter debug: msg: >- {{ values | map('zip', ['k1', 'k2', 'k3']) | map('map', 'reverse') | map('community.general.dict') }} vars: values: - - foo - 23 - a - - bar - 42 - b ``` -------------------------------- ### Basic ModuleHelper Implementation Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_modulehelper.rst Demonstrates a simple Ansible module using ModuleHelper, including argument specification and basic logic. Use this as a starting point for creating new modules. ```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() ``` -------------------------------- ### Run Keycloak Docker Container with Concrete Values Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_authz_authorization_scope/readme.adoc An example of the Docker run command with specific values for the Keycloak URL path, admin user, and password. ```bash docker run --name mykeycloak -p 8080:8080 -e KC_HTTP_RELATIVE_PATH=/auth -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password quay.io/keycloak/keycloak:20.0.2 start-dev ``` -------------------------------- ### Run Flatpak Application Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Executes the installed Flatpak application. This command launches the application in an isolated environment. ```bash flatpak run com.dummy.App$NUM ``` -------------------------------- ### ZFS List Output Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_hooks.rst This output from 'zfs list' shows the structure of iocage pools and datasets. It helps in understanding the path where jail files are located, such as /zroot/iocage/jails/srv_1/root. ```console shell> zfs list | grep /zroot/iocage zroot/iocage 4.69G 446G 5.08M /zroot/iocage zroot/iocage/download 927M 446G 384K /zroot/iocage/download zroot/iocage/download/14.1-RELEASE 465M 446G 465M /zroot/iocage/download/14.1-RELEASE zroot/iocage/download/14.2-RELEASE 462M 446G 462M /zroot/iocage/download/14.2-RELEASE zroot/iocage/images 384K 446G 384K /zroot/iocage/images zroot/iocage/jails 189M 446G 480K /zroot/iocage/jails zroot/iocage/jails/srv_1 62.9M 446G 464K /zroot/iocage/jails/srv_1 zroot/iocage/jails/srv_1/root 62.4M 446G 3.53G /zroot/iocage/jails/srv_1/root zroot/iocage/jails/srv_2 62.8M 446G 464K /zroot/iocage/jails/srv_2 zroot/iocage/jails/srv_2/root 62.3M 446G 3.53G /zroot/iocage/jails/srv_2/root zroot/iocage/jails/srv_3 62.8M 446G 464K /zroot/iocage/jails/srv_3 zroot/iocage/jails/srv_3/root 62.3M 446G 3.53G /zroot/iocage/jails/srv_3/root zroot/iocage/log 688K 446G 688K /zroot/iocage/log zroot/iocage/releases 2.93G 446G 384K /zroot/iocage/releases zroot/iocage/releases/14.2-RELEASE 2.93G 446G 384K /zroot/iocage/releases/14.2-RELEASE zroot/iocage/releases/14.2-RELEASE/root 2.93G 446G 2.88G /zroot/iocage/releases/14.2-RELEASE/root zroot/iocage/templates 682M 446G 416K /zroot/iocage/templates zroot/iocage/templates/ansible_client 681M 446G 432K /zroot/iocage/templates/ansible_client zroot/iocage/templates/ansible_client/root 681M 446G 3.53G /zroot/iocage/templates/ansible_client/root ``` -------------------------------- ### Keep Keys Matching 'equal' Strategy Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst This example demonstrates keeping keys that exactly match the provided target values. The 'matching_parameter' is set to 'equal'. ```yaml+jinja mp: equal target: ['k0_x0', 'k1_x1'] result: "{{ input | community.general.keep_keys(target=target, matching_parameter=mp) }}" ``` -------------------------------- ### Python Interpreter Command Line Example Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_cmdrunner.rst Illustrates the command line generated when the 'python' parameter is set to a specific interpreter version. ```shell /usr/bin/python3.12 -m django ... ``` -------------------------------- ### Obtain and Print Volume Facts Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_modulehelper.rst Example of how to call a module that returns facts and how to access those facts in a subsequent task. ```yaml - name: Obtain volume facts some.collection.volume_facts: # parameters - name: Print volume facts debug: msg: Volume fact is {{ ansible_facts.volume_facts.volume }} ``` -------------------------------- ### Implementing StateModuleHelper for gconftool2 Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_modulehelper.rst This example shows how to implement StateModuleHelper for a module with 'present' and 'absent' states. It demonstrates setting module variables and defining state-specific methods. ```python from ansible_collections.community.general.plugins.module_utils._module_helper import StateModuleHelper class GConftool(StateModuleHelper): ... module = dict( ... ) def __init_module__(self): self.runner = gconftool2_runner(self.module, check_rc=True) ... self.vars.set('previous_value', self._get(), fact=True) self.vars.set('value_type', self.vars.value_type) self.vars.set('_value', self.vars.previous_value, output=False, change=True) self.vars.set_meta('value', initial_value=self.vars.previous_value) self.vars.set('playbook_value', self.vars.value, fact=True) ... def state_absent(self): with self.runner("state key", output_process=self._make_process(False)) as ctx: ctx.run() self.vars.set('run_info', ctx.run_info, verbosity=4) self.vars.set('new_value', None, fact=True) self._value = None def state_present(self): with self.runner("direct config_source value_type state key value", output_process=self._make_process(True)) as ctx: ctx.run() self.vars.set('run_info', ctx.run_info, verbosity=4) self.vars.set('new_value', self._get(), fact=True) self._value = self.vars.new_value ``` -------------------------------- ### Define input lists for merging Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst These are the initial lists of dictionaries used in the merging examples. ```yaml list1: - {name: foo, extra: true} - {name: bar, extra: false} - {name: meh, extra: true} list2: - {name: foo, path: /foo} - {name: baz, path: /baz} ``` -------------------------------- ### Provision Alicloud ECS Instances Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_alicloud.rst Use the ali_instance module to create ECS instances with specified configurations. This example demonstrates creating 5 instances tagged 'NewECS' and allocating public IP addresses. ```yaml+jinja # alicloud_setup.yml - hosts: localhost connection: local tasks: - name: Create a set of instances community.general.ali_instance: instance_type: ecs.n4.small image_id: "{{ ami_id }}" instance_name: "My-new-instance" instance_tags: Name: NewECS Version: 0.0.1 count: 5 count_tag: Name: NewECS allocate_public_ip: true max_bandwidth_out: 50 register: create_instance ``` -------------------------------- ### Remove Keys by Exact Match Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst This example demonstrates removing keys that exactly match the specified target values. The `matching_parameter` is set to 'equal'. ```yaml+jinja mp: equal target: ['k0_x0', 'k1_x1'] result: "{{ input | community.general.remove_keys(target=target, matching_parameter=mp) }}" ``` -------------------------------- ### Build and Run Keycloak Custom Policy Test Instance Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_authz_custom_policy/readme.adoc Use these shell commands to build a Docker image with custom Keycloak policies and run a container for integration testing. Ensure you have Podman or Docker installed. ```shell ./build-policy.sh podman build --tag keycloak_authz_custom_policy_test:1.0.0 . podman rm mykeycloak && podman run --name mykeycloak -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password -e KC_HTTP_RELATIVE_PATH=/auth localhost/keycloak_authz_custom_policy_test:1.0.0 start-dev ``` -------------------------------- ### UTHelper Test Case Specification in YAML Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_uthelper.rst Example of a test case defined in YAML format for UTHelper. This includes input parameters, expected output, and mock configurations for external commands. ```yaml test_cases: - id: test_ansible_module flags: diff: true input: state: present name: Roger the Shrubber output: shrubbery: looks: nice price: not too expensive changed: true diff: before: shrubbery: null after: shrubbery: looks: nice price: not too expensive mocks: run_command: - command: [/testbin/shrubber, --version] rc: 0 out: "2.80.0\n" err: '' - command: [/testbin/shrubber, --make-shrubbery] rc: 0 out: 'Shrubbery created' err: '' ``` -------------------------------- ### Select SCSI controller with fewest disks using community.general.counter Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide_abstract_informations_counting_elements_in_sequence.rst This example demonstrates how to use the counter filter in conjunction with other filters to select a SCSI controller based on the number of disks attached. It counts adapters, filters those with less than 4 disks, sorts them by disk count, and selects the first one. ```yaml+jinja - name: Get ID of SCSI controller(s) with less than 4 disks attached and choose the one with the least disks debug: msg: >- {{ ( disks | dict2items | map(attribute='value.adapter') | list | community.general.counter | dict2items | rejectattr('value', '>=', 4) | sort(attribute='value') | first ).key }} vars: disks: sda: adapter: scsi_1 sdb: adapter: scsi_1 sdc: adapter: scsi_1 sdd: adapter: scsi_1 sde: adapter: scsi_2 sdf: adapter: scsi_3 sdg: adapter: scsi_3 ``` -------------------------------- ### Ansible playbook output showing iocage tags and groups Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_tags.rst Example output from the Ansible playbook, illustrating the resolved 'iocage_tags' for each host and the dynamically created groups. ```console PLAY [all] ********************************************************************************************************** TASK [debug] ******************************************************************************************************** ok: [srv_1] => iocage_tags: project: foo vmm: iocage_02 ok: [srv_2] => iocage_tags: project: foo vmm: iocage_02 ok: [srv_3] => iocage_tags: project: bar vmm: iocage_02 TASK [debug] ******************************************************************************************************** ok: [srv_1] => msg: |- all: ['srv_1', 'srv_2', 'srv_3'] ungrouped: [] vmm_iocage_02: ['srv_1', 'srv_2', 'srv_3'] project_foo: ['srv_1', 'srv_2'] project_bar: ['srv_3'] PLAY RECAP ********************************************************************************************************** ``` -------------------------------- ### Replace Keys Using Regex Matching Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst This example demonstrates replacing keys that match a regular expression. The 'matching_parameter' is set to 'regex', and the 'before' attribute contains the regex pattern. ```yaml result: - a0: A0 a1: B0 k2_x2: - C0 k3_x3: foo - a0: A1 a1: B1 k2_x2: - C1 k3_x3: bar ``` ```yaml+jinja mp: regex target: - {after: a0, before: ^.*0_x.*$} - {after: a1, before: ^.*1_x.*$} result: "{{ input | community.general.replace_keys(target=target, matching_parameter=mp) }}" ``` -------------------------------- ### Initialize and Use VarDict Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_vardict.rst Demonstrates basic initialization and setting of variables using attribute access, dictionary-like access, and the set() method. ```python from ansible_collections.community.general.plugins.module_utils._vardict import VarDict vars = VarDict() # Next 3 statements are equivalent vars.abc = 123 vars["abc"] = 123 vars.set("abc", 123) vars.xyz = "bananas" vars.ghi = False ``` -------------------------------- ### Configure Scaleway Dynamic Inventory Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_scaleway.rst This configuration file sets up the Scaleway dynamic inventory plugin. It specifies the regions and tags to filter Scaleway resources. Ensure the `community.general.scaleway` plugin is installed. ```yaml plugin: community.general.scaleway regions: - ams1 - par1 tags: - web_server ``` -------------------------------- ### Create Hello World Executable Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Creates a simple shell script that outputs 'hello world'. This script will be packaged into a Flatpak application. ```bash echo $'#!/bin/sh\necho hello world' > hello.sh ``` -------------------------------- ### Install packet-python Package Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_packet.rst Install the packet-python package using pip. This is a prerequisite for using the Packet modules. ```console $ pip install packet-python ``` -------------------------------- ### Initialize and Build Flatpak App Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Initializes a Flatpak application directory, copies the executable into it, and finalizes the build. Replace NUM with a unique integer for each distinct Flatpak. ```bash export NUM=1 flatpak build-init appdir$NUM com.dummy.App$NUM org.freedesktop.Sdk org.freedesktop.Platform 1.6; flatpak build appdir$NUM mkdir /app/bin; flatpak build appdir$NUM install --mode=750 hello.sh /app/bin; flatpak build-finish --command=hello.sh appdir$NUM ``` -------------------------------- ### List iocage jails with detailed information Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_dhcp.rst Run this command on the iocage host to display a list of all jails, including their JID, name, boot status, state, release, IP4 and IP6 addresses, template, and basejail status. ```console shell> iocage list -l +-----+-------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ | JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | +=====+=======+======+=======+======+=================+====================+=====+================+==========+ | 204 | srv_1 | off | up | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.183 | - | ansible_client | no | +-----+-------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ | 205 | srv_2 | off | up | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.204 | - | ansible_client | no | +-----+-------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ | 206 | srv_3 | off | up | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.169 | - | ansible_client | no | +-----+-------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ ``` -------------------------------- ### Create UTHelper from Test Specification File Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_uthelper.rst Use `from_file` to initialize a UTHelper instance by reading a test specification from a YAML file. The file handle must be opened in read mode. ```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]) ``` -------------------------------- ### Format Code with Ruff Source: https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md Run all configured formatters using nox. If discrepancies arise, re-generate the virtual environment. ```bash # Run all configured formatters: nox -Re formatters ``` ```bash # If you notice discrepancies between your local formatter and CI, you might # need to re-generate the virtual environment: nox -e formatters ``` -------------------------------- ### Create Flatpak Repository Metadata File Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Creates a .flatpakrepo file, which describes the Flatpak repository itself. It includes the repository's title, URL, and GPG key. ```ini [Flatpak Repo] Title=Dummy Repo Url=file:///tmp/flatpak/repo Comment=Dummy repo for ansible module integration testing Description=Dummy repo for ansible module integration testing GPGKey={{ base64-encoded public KEY }} ``` -------------------------------- ### Create iocage inventory file with sudo Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/guide_iocage_inventory_dhcp.rst Use this configuration to create an inventory file for iocage jails, enabling sudo access for the connection. ```yaml plugin: community.general.iocage host: 10.1.0.73 user: admin sudo: true ``` -------------------------------- ### Remove Keys by Prefix Match Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst Use this to remove keys that start with any of the specified prefixes. The `matching_parameter` is set to 'starts_with'. ```yaml+jinja mp: starts_with target: ['k0', 'k1'] result: "{{ input | community.general.remove_keys(target=target, matching_parameter=mp) }}" ``` -------------------------------- ### Stop Keycloak Server Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_realm_users_info/README.md Stops the Keycloak server instance started for integration testing. This command cleans up the running container. ```bash podman|docker stop mykeycloak ``` -------------------------------- ### Run Keycloak Server with Docker Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/keycloak_userprofile/readme.adoc Launches a Keycloak server instance using Docker. Configure the relative path for Keycloak, the admin username, and the admin password using environment variables. ```bash docker run --name mykeycloak -p 8080:8080 -e KC_HTTP_RELATIVE_PATH= -e KEYCLOAK_ADMIN= -e KEYCLOAK_ADMIN_PASSWORD= quay.io/keycloak/keycloak:24.0.5 start-dev ``` ```bash docker run --name mykeycloak -p 8080:8080 -e KC_HTTP_RELATIVE_PATH=/auth -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=password quay.io/keycloak/keycloak:24.0.5 start-dev ``` -------------------------------- ### Remove Keys by Suffix Match Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst This example shows how to remove keys that end with any of the specified suffixes. The `matching_parameter` is set to 'ends_with'. ```yaml+jinja mp: ends_with target: ['x0', 'x1'] result: "{{ input | community.general.remove_keys(target=target, matching_parameter=mp) }}" ``` -------------------------------- ### Remove Keys by Prefix Match (Single) Source: https://github.com/ansible-collections/community.general/blob/main/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst Use this to remove keys that start with a single specified prefix. The `matching_parameter` is set to 'starts_with'. ```yaml+jinja mp: starts_with target: k0 ``` -------------------------------- ### Add Local Repository using .flatpakrepo File Source: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/setup_flatpak_remote/README.md Adds the local Flatpak repository using its .flatpakrepo metadata file. This is a convenient way to add repositories when the metadata file is available. ```bash flatpak --system remote-add dummy-repo /tmp/flatpak/repo/dummy-repo.flatpakrepo ```