Ansible教程:在Playbook中使用模块


配置防火墙

yaml
---
- hosts: dev
  tasks:
    - name: allow https service
      ansible.posix.firewalld:
        service: https
        permanent: yes
        state: enabled
    - name: ban port 8081/tcp
      ansible.posix.firewalld:
        port: 8081/tcp
        permanent: yes
        state: disabled        

template模块的使用

根据模板动态在被控主机上创建index.html:

yaml
---
- hosts: dev
  tasks:
    - name: template demo
      template:
        src: demo.html
        dest: /tmp/index.html

几个注意事项:

  • 不能使用index.html作为文件名,否则会找不到。
  • Ansible会自动在当前目录下的templates及template子目录中寻找指定的文件,因此可以添加路径。比如:如果文件templates/demo.html存在,则只需指定 src: demo.html 即可。当然,也可以使用类似 ./templates/demo.html 的格式。

文章作者: 逻思
版权声明: 本博客所有文章除特別声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 逻思 !