Docs: add code-blocks to User Guide modules_intro (#75932)

pull/76012/head
Nathan Tsai 3 years ago committed by GitHub
parent a4a7a34893
commit a2ff765e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,7 +5,9 @@ Introduction to modules
Modules (also referred to as "task plugins" or "library plugins") are discrete units of code that can be used from the command line or in a playbook task. Ansible executes each module, usually on the remote managed node, and collects return values. In Ansible 2.10 and later, most modules are hosted in collections. Modules (also referred to as "task plugins" or "library plugins") are discrete units of code that can be used from the command line or in a playbook task. Ansible executes each module, usually on the remote managed node, and collects return values. In Ansible 2.10 and later, most modules are hosted in collections.
You can execute modules from the command line:: You can execute modules from the command line.
.. code-block:: shell-session
ansible webservers -m service -a "name=httpd state=started" ansible webservers -m service -a "name=httpd state=started"
ansible webservers -m ping ansible webservers -m ping
@ -13,12 +15,16 @@ You can execute modules from the command line::
Each module supports taking arguments. Nearly all modules take ``key=value`` arguments, space delimited. Some modules take no arguments, and the command/shell modules simply take the string of the command you want to run. Each module supports taking arguments. Nearly all modules take ``key=value`` arguments, space delimited. Some modules take no arguments, and the command/shell modules simply take the string of the command you want to run.
From playbooks, Ansible modules are executed in a very similar way:: From playbooks, Ansible modules are executed in a very similar way.
.. code-block:: yaml
- name: reboot the servers - name: reboot the servers
command: /sbin/reboot -t now command: /sbin/reboot -t now
Another way to pass arguments to a module is using YAML syntax, also called 'complex args' :: Another way to pass arguments to a module is using YAML syntax, also called 'complex args'.
.. code-block:: yaml
- name: restart webserver - name: restart webserver
service: service:
@ -27,11 +33,15 @@ Another way to pass arguments to a module is using YAML syntax, also called 'com
All modules return JSON format data. This means modules can be written in any programming language. Modules should be idempotent, and should avoid making any changes if they detect that the current state matches the desired final state. When used in an Ansible playbook, modules can trigger 'change events' in the form of notifying :ref:`handlers <handlers>` to run additional tasks. All modules return JSON format data. This means modules can be written in any programming language. Modules should be idempotent, and should avoid making any changes if they detect that the current state matches the desired final state. When used in an Ansible playbook, modules can trigger 'change events' in the form of notifying :ref:`handlers <handlers>` to run additional tasks.
You can access the documentation for each module from the command line with the ansible-doc tool:: You can access the documentation for each module from the command line with the ansible-doc tool.
.. code-block:: shell-session
ansible-doc yum ansible-doc yum
For a list of all available modules, see the :ref:`Collection docs <list_of_collections>`, or run the following at a command prompt:: For a list of all available modules, see the :ref:`Collection docs <list_of_collections>`, or run the following at a command prompt.
.. code-block:: shell-session
ansible-doc -l ansible-doc -l

Loading…
Cancel
Save