4

I can't find any info about any command to run, in order to show/confirm what add-on Ansible modules or built-in Ansible modules are installed on my control-node?

Regarding built-ins, I know that there are web-pages that list these things but surely they must be version-dependent, which means that I'd need to first verify my local Ansible version and then find a web-page that lists all built-ins for that specific version — i.e., very inefficient.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
John Reed Avery
  • 121
  • 1
  • 7

2 Answers2

2

ansible-doc --list.

$ ansible-doc --list | head
add_host                                                                            Add a host (and alternatively a group) to the ansible-playbook in-memory ...
amazon.aws.aws_az_info                                                              Gather information about availability zon...
amazon.aws.aws_caller_info                                                          Get information about the user and account being used to make ...
amazon.aws.aws_s3                                                                   manage obje...
amazon.aws.cloudformation                                                           Create or delete an AWS CloudFormat...
amazon.aws.cloudformation_info                                                      Obtain information about an AWS CloudFormat...
amazon.aws.ec2                                                                      create, terminate, start or stop an instan...
amazon.aws.ec2_ami                                                                  Create or destroy an image (AM...
amazon.aws.ec2_ami_info                                                             Gather information about...
amazon.aws.ec2_eni                                                                  Create and optionally attach an Elastic Network Interface (ENI) to an...

This can also be used to list available plugins of other types, e.g. to show all lookup plugins you would run ansible-doc -t lookup --list.

flowerysong
  • 2,921
  • 4
  • 13
  • Thanks, flowerysong, for that reply. However, I've seen a BUNCH of documentation that clearly indicates that plugins and modules are not the same thing. And the output, of "ansible-doc --help", says that the "--list" option is used to "List available plugins." So, I cannot tell that your suggestion provides me with the info that I need. – John Reed Avery Apr 06 '23 at 17:51
  • Well, that's a very silly comment. Modules are a type of plugin, and they're the default that's displayed by `ansible-doc`. You can also just look at the output and see that it's listing modules. – flowerysong Apr 06 '23 at 20:15
  • 1
    Sorry, flowerysong. I'm new to Ansible and most-or-all of the Ansible-documentation, that I have seen, does not come anywhere close to making it clear that a module is a type of plugin. I intended no offence. Also, it's not true that I can "just look at the output and see that it's listing modules", because I am so new to Ansible that I cannot readily tell the difference between a module-name and a non-module-plugin name, assuming that there is some standard difference to the way they are named, which I am also too-new-to-Ansible to know. – John Reed Avery Apr 06 '23 at 21:00
  • So why was your instinct to assume that the output wasn't modules? The documentation that I pointed you to says that the command displays modules. The output shows a list of modules, which you can verify by cross-referencing it with any other list of modules that you've found (like the web pages that you referenced in your question.) You had no reason to think that it wasn't a list of modules, which is why your comment was so strange. – flowerysong Apr 06 '23 at 22:25
  • I'm sorry @flowerysong. I did not notice that you pointed me to any documentation. I saw only that you pointed me to a command. And my first reply to you included the fact that the output, of "ansible-doc --help", says that the "--list" option is used to "List available plugins." I had already read that before you gave me your first message. So, I wasn't making any assumptions. I was following what I had read. And I did not have time to pour through long lists of "modules" and "plugins" to see what matches what. Please forgive me for offending you. I hope we can let this go, now. Tx. – John Reed Avery Apr 07 '23 at 23:14
1

You can create the dictionary of installed collections and modules

- hosts: localhost

  vars:

    ansible_doc: /home/admin/.local/bin/ansible-doc
    modules_all: "{{ (out.stdout|from_yaml).keys()|list }}"
    modules_str: |
      {% for i in modules_all %}
      {% set arr = i.split('.') %}
      - {collection: {{ arr[:-1]|join('.')|d('ansible.builtin', true) }}, module: {{ arr[-1] }}}
      {% endfor %}
    modules_grp: "{{ modules_str|from_yaml|groupby('collection') }}"
    collections_list: "{{ modules_grp|map('first') }}"
    modules_lists: "{{ modules_grp|map('last')|map('map', attribute='module') }}"
    collections: "{{ dict(collections_list|zip(modules_lists)) }}"

  tasks:

    - command: "{{ ansible_doc }} -t module -l -j"
      register: out

    - debug:
        var: out.stdout_lines
      when: false
    - debug:
        var: out.stdout
      when: false
    - debug:
        var: modules_all
      when: false
    - debug:
        var: modules_str
      when: false
    - debug:
        var: collections.keys()|list|to_yaml
      when: true
    - debug:
        var: collections['ansible.builtin']|to_yaml
      when: true
    - debug:
        var: collections['community.digitalocean']|to_yaml
      when: true
    - debug:
        var: collections['community.general']|to_yaml
      when: true

gives the list of the collections

  collections.keys()|list|to_yaml: |-
    [amazon.aws, ansible.builtin, ansible.legacy, ansible.netcommon, ansible.posix, ansible.utils,
      ansible.windows, arista.eos, awx.awx, azure.azcollection, check_point.mgmt, chocolatey.chocolatey,
      cisco.aci, cisco.asa, cisco.dnac, cisco.intersight, cisco.ios, cisco.iosxr, cisco.ise,
      cisco.meraki, cisco.mso, cisco.nso, cisco.nxos, cisco.nxos.storage, cisco.ucs, cloud.common,
      cloudscale_ch.cloud, community.aws, community.ciscosmb, community.crypto, community.digitalocean,
      community.dns, community.docker, community.fortios, community.general, community.google,
      community.grafana, community.hashi_vault, community.hrobot, community.kubevirt,
      community.libvirt, community.mongodb, community.mysql, community.network, community.okd,
      community.postgresql, community.proxysql, community.rabbitmq, community.routeros,
      community.sap, community.sap.database.saphana, community.sap.files, community.sap.identity,
      community.sap.system, community.sap_libs, community.skydive, community.sops, community.vmware,
      community.windows, community.zabbix, containers.podman, cyberark.pas, dellemc.enterprise_sonic,
      dellemc.openmanage, dellemc.os10, dellemc.os6, dellemc.os9, dellemc.powerflex, dellemc.unity,
      f5networks.f5_modules, fortinet.fortimanager, fortinet.fortios, frr.frr, gluster.gluster,
      google.cloud, grafana.grafana, hetzner.hcloud, hpe.nimble, ibm.qradar, ibm.spectrum_virtualize,
      infinidat.infinibox, infoblox.nios_modules, inspur.ispim, inspur.sm, junipernetworks.junos,
      kubernetes.core, lowlydba.sqlserver, mellanox.onyx, netapp.aws, netapp.azure, netapp.cloudmanager,
      netapp.elementsw, netapp.ontap, netapp.storagegrid, netapp.um_info, netapp_eseries.santricity,
      netbox.netbox, ngine_io.cloudstack, ngine_io.exoscale, ngine_io.vultr, openstack.cloud,
      openvswitch.openvswitch, ovirt.ovirt, purestorage.flasharray, purestorage.flashblade,
      purestorage.fusion, sensu.sensu_go, servicenow.servicenow, splunk.es, t_systems_mms.icinga_director,
      theforeman.foreman, vmware.vmware_rest, vultr.cloud, vyos.vyos, wti.remote]

Modules ansible.builtin

  collections['ansible.builtin']|to_yaml: |-
    [_include, add_host, apt, apt_key, apt_repository, assemble, assert, async_status,
      blockinfile, command, copy, cron, debconf, debug, dnf, dpkg_selections, expect,
      fail, fetch, file, find, gather_facts, get_url, getent, git, group, group_by, hostname,
      import_playbook, import_role, import_tasks, include_role, include_tasks, include_vars,
      iptables, known_hosts, lineinfile, meta, package, package_facts, pause, ping, pip,
      raw, reboot, replace, rpm_key, script, service, service_facts, set_fact, set_stats,
      setup, shell, slurp, stat, subversion, systemd, systemd_service, sysvinit, tempfile,
      template, unarchive, uri, user, validate_argument_spec, wait_for, wait_for_connection,
      yum, yum_repository]

For example, collection community.digitalocean

  collections['community.digitalocean']|to_yaml: |-
    [digital_ocean, digital_ocean_account_facts, digital_ocean_account_info, digital_ocean_balance_info,
      digital_ocean_block_storage, digital_ocean_cdn_endpoints, digital_ocean_cdn_endpoints_info,
      digital_ocean_certificate, digital_ocean_certificate_facts, digital_ocean_certificate_info,
      digital_ocean_database, digital_ocean_database_info, digital_ocean_domain, digital_ocean_domain_facts,
      digital_ocean_domain_info, digital_ocean_domain_record, digital_ocean_domain_record_info,
      digital_ocean_droplet, digital_ocean_droplet_info, digital_ocean_firewall, digital_ocean_firewall_facts,
      digital_ocean_firewall_info, digital_ocean_floating_ip, digital_ocean_floating_ip_facts,
      digital_ocean_floating_ip_info, digital_ocean_image_facts, digital_ocean_image_info,
      digital_ocean_kubernetes, digital_ocean_kubernetes_info, digital_ocean_load_balancer,
      digital_ocean_load_balancer_facts, digital_ocean_load_balancer_info, digital_ocean_monitoring_alerts,
      digital_ocean_monitoring_alerts_info, digital_ocean_project, digital_ocean_project_info,
      digital_ocean_region_facts, digital_ocean_region_info, digital_ocean_size_facts,
      digital_ocean_size_info, digital_ocean_snapshot, digital_ocean_snapshot_facts, digital_ocean_snapshot_info,
      digital_ocean_spaces, digital_ocean_spaces_info, digital_ocean_sshkey, digital_ocean_sshkey_facts,
      digital_ocean_sshkey_info, digital_ocean_tag, digital_ocean_tag_facts, digital_ocean_tag_info,
      digital_ocean_volume_facts, digital_ocean_volume_info, digital_ocean_vpc, digital_ocean_vpc_info]

Top 10

    - debug:
        msg: |
          Top 10
          ------
          {% for i in range(10) %}
          {{ collections_len_list[i].key }}: {{ collections_len_list[i].value }}
          {% endfor %}
      vars:
        modules_lists_len: "{{ modules_lists|map('length') }}"
        collections_len: "{{ dict(collections_list|zip(modules_lists_len)) }}"
        collections_len_list: "{{ collections_len|dict2items|sort(attribute='value', reverse=true) }}"

gives

    Top 10
    ------
    fortinet.fortimanager: 994
    fortinet.fortios: 646
    community.general: 571
    cisco.ise: 383
    cisco.dnac: 354
    community.network: 315
    azure.azcollection: 276
    f5networks.f5_modules: 178
    check_point.mgmt: 174
    google.cloud: 170
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • **NOW** we're getting somewhere! Thanks, Vladimir! But now I have another confusion. I just now proved that, on my control-node the outputs of "`ansible-doc --list`" and of "`ansible-doc -t module -l`" are **precisely** the **same**. So, I'm left with continuing to wonder what is the difference between a "module" and any of the various types of "plugin", as described by various sources I have found. But I guess I'll have to learn that simply by spending many hours playing/working with Ansible in various ways. Thanks again. – John Reed Avery Apr 06 '23 at 18:07
  • 1
    Everything is a plugin. Take a look at the source. For example [community.general](https://github.com/ansible-collections/community.general/tree/main/plugins) plugins. – Vladimir Botka Apr 06 '23 at 18:12
  • Cool. Thanks again, Vladimir! I've been wondering about that. This is a helpful start. – John Reed Avery Apr 06 '23 at 18:15