Ayuda de uso del módulo ansible de Ansible

1. Ver todas las plantillas

[root@Ansible ~]# ansible-doc -l        查看所有模块
[root@Ansible ~]# ansible-doc -l | grep -w "service"
service                                                       Manage services

2. Ver la documentación de los módulos relevantes

[root@Ansible ~]# ansible-doc service
> SERVICE    (/usr/lib/python2.7/site-packages/ansible/modules/system/service.py)

        Controls services on remote hosts. Supported init systems include BSD init, OpenRC, SysV, Solaris SMF, systemd, upstart.
        For Windows targets, use the [win_service] module instead.

  * This module is maintained by The Ansible Core Team
  * note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

- arguments
        Additional arguments provided on the command line.
        (Aliases: args)[Default: (null)]
        type: str

- enabled
        Whether the service should start on boot.
        *At least one of state and enabled are required.*
        [Default: (null)]
        type: bool

= name
        Name of the service.

        type: str

- pattern
        If the service does not respond to the status command, name a substring to look for as would be found in the output of
        the `ps' command as a stand-in for a status result.
        If the string is found, the service will be assumed to be started.
        [Default: (null)]
        type: str
        version_added: 0.7

- runlevel
        For OpenRC init scripts (e.g. Gentoo) only.
        The runlevel that this service belongs to.
        [Default: default]
        type: str

- sleep
        If the service is being `restarted' then sleep this many seconds between the stop and start command.
        This helps to work around badly-behaving init scripts that exit immediately after signaling a process to stop.
        Not all service managers support sleep, i.e when using systemd this setting will be ignored.
        [Default: (null)]
        type: int
        version_added: 1.3

- state
        `started'/`stopped' are idempotent actions that will not run commands unless necessary.
        `restarted' will always bounce the service.
        `reloaded' will always reload.
        *At least one of state and enabled are required.*
        Note that reloaded will start the service if it is not already started, even if your chosen init system wouldn't
        normally.
        (Choices: reloaded, restarted, started, stopped)[Default: (null)]
        type: str

- use
        The service module actually uses system specific modules, normally through auto detection, this setting can force a
        specific module.
        Normally it uses the value of the 'ansible_service_mgr' fact and falls back to the old 'service' module when none
        matching is found.
        [Default: auto]
        type: str
        version_added: 2.2

Tres, uso del módulo de servicio

ansible songxin_test -m service -a "name=ntpd.service state=started enabled=yes" -u cedar -b

-m service :                使用service模块
-a :                              输入模块的参数
name=ntpd.service    服务名
state=stared               启动服务
enabled=yes              开机启动

Supongo que te gusta

Origin blog.51cto.com/12965094/2597410
Recomendado
Clasificación