Module Option Query Instructions
Current Ansible Version
[root@awx-1 ansible]# ansible --version
ansible [core 2.16.3]
config file = /root/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.12/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.12.8 (main, Dec 12 2024, 16:30:29) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] (/usr/bin/python3.12)
jinja version = 3.1.2
libyaml = True
Ansible Version: 2.16.3
Python Version: 3.12.8
In the following sections, I will write about some common options and usage examples for frequently used modules, all based on this version.
Querying Modules with ansible-doc
You can list all available modules with <span>ansible-doc -l</span>:
[root@awx-1 ansible]# ansible-doc -l | grep ansible.builtin | head
ansible.builtin.add_host Add a host (and alternatively a group) to the ansible-playbo...
ansible.builtin.apt ...
ansible.builtin.apt_key Ad...
ansible.builtin.apt_repository Add and r...
ansible.builtin.assemble Assemble configuratio...
ansible.builtin.assert Asserts give...
ansible.builtin.async_status Obtain statu...
ansible.builtin.blockinfile Insert/update/remove a text block surr...
ansible.builtin.command Execu...
ansible.builtin.copy Copy fil...
You can query the usage instructions for <span>ansible.builtin.yum</span> with <span>ansible-doc ansible.builtin.yum</span>:
[root@awx-1 ansible]# ansible-doc ansible.builtin.yum
The queried information includes the following important sections (for example, you can search for examples using <span>/EXAMPLE</span>):
- • OPTIONS: Available options for OPTIONS have two important attributes:
- •
<span>type</span>: Defines the data structure of the option (<span>list/str/bool</span>, etc.)For example, the
<span>name</span>option of the<span>ansible.builtin.yum</span>module has a<span>type</span>of<span>list</span>, so it is written as follows:- name: Download the nginx package but do not install it ansible.builtin.yum: name: - nginx - mysql state: latest - •
<span>list</span>: List - •
<span>str</span>: String - •
<span>bool</span>: Boolean (<span>yes/no</span>,<span>true/false</span>) - •
<span>default</span>: Defines the default value of the option - • EXAMPLES: Usage examplesEXAMPLE lists common methods, which can be referenced when not using the module.
You can list all options of the module with <span>ansible-doc -s ansible.builtin.yum</span>:
[root@awx-1 ansible]# ansible-doc -s ansible.builtin.yum
My usual practice is to first run
<span>ansible-doc ansible.builtin.yum</span>, and then search for EXAMPLE, and directly copy the examples.