官术网_书友最值得收藏!

Ansible modules

Ansible ships with a number of modules (called the module library) that can be executed directly on remote hosts or through playbooks.Tasks in playbooks call modules to do the work. 

Ansible has many modules, most of which are community contributed and maintained. Core modules are maintained by the Ansible core engineering team and will always ship with Ansible itself.

Users can also write their own modules. These modules can control system resources, like services, packages, or files (anything really), or handle executing system commands.

Here is the list of modules available by Ansible: http://docs.ansible.com/ansible/latest/modules_by_category.html#module-index.
If you use Dash (https://kapeli.com/dash) or Zeal (https://zealdocs.org/), you can download the offline version for easy reference.

Modules can be executed via the command line as well. We will be using modules to write all the tasks inside our playbooks. All modules technically return JSON format data. 

Modules should be idempotent and should avoid making any changes if they detect that the current state matches the desired final state. When using Ansible playbooks, these modules can trigger change events in the form of notifying handlers to run additional tasks.

Documentation for each module can be accessed from the command line with the ansible-doc tool:

$ ansible-doc apt

We can list all the modules available on our host:

$ ansible-doc -l

Start the Apache web server on all nodes grouped under webservers by executing the httpd module. Note the use of the -m flag:

$ ansible webservers -m service -a "name=httpd state=started"

This snippet shows the exact same command but inside a playbook in YAML syntax:

- name: restart webserver
  service:
    name: httpd
    state: started

Each module contains multiple parameters and options, get to know more about the features of the modules by looking at their documentation and examples.

主站蜘蛛池模板: 阳山县| 获嘉县| 郑州市| 大姚县| 商南县| 周口市| 通辽市| 贵南县| 榆树市| 琼中| 铜梁县| 滨州市| 肥乡县| 黔西县| 黎城县| 洛浦县| 湘阴县| 行唐县| 孝感市| 武威市| 汝南县| 苏尼特左旗| 海晏县| 阿尔山市| 罗田县| 博兴县| 巩义市| 平阴县| 仲巴县| 黄骅市| 徐汇区| 西丰县| 太仆寺旗| 扬州市| 通山县| 鹤庆县| 汕头市| 合川市| 宜昌市| 繁昌县| 化德县|