Ansible模块使用详解

模块使用

通过命令行来执行三个不同的模块:

ansible webservers -m service -a "name=httpd state=started"
ansible webservers -m ping
ansible webservers -m command -a "/sbin/reboot -t now"

在 playbook 中, Ansible 模块以类似的方式执行:

- name: reboot the servers
  action: command /sbin/reboot -t now

也可以简写成:

- name: reboot the servers
  command: /sbin/reboot -t now

另一种给模块传递参数的方式是使用 yaml 语法,这也被称为 ‘complex args’:

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

每个模块的文档能够通过命令行的 ansible-doc 工具来获取:

ansible-doc ping

列出所有已安装的模块文档:

ansible-doc -l

官方模块访问地址

https://docs.ansible.com/ansible/latest/modules/
posted @ 2020-10-28 15:23  Varden  阅读(335)  评论(0编辑  收藏  举报