运维开发网

Ansible 之 ansible的模块使用

运维开发网 https://www.qedev.com 2021-01-20 13:44 出处:51CTO 作者:wx592bc92b285c7
一、查看所有模板[[email protected]~]#ansible-doc-l查看所有模块[[email protected]~]#ansible-doc-l|grep-w"service"serviceManageservices二、查看相关模块的使用文档[[email protected]~]#ansible-docservice>SERVICE(/usr/lib/python2.7/site-packages

一、查看所有模板

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

二、查看相关模块的使用文档

[[email protected] ~]# 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

三、service 模块使用

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              开机启动

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号