列举出5个常用的ansible-playbook 模块并简述其用法
- file模块:用于管理文件和目录,包括创建、删除、修改、复制等操作。 例如,使用file模块创建一个文件:
- name: Create a file
file:
path: /root/hello.txt
state: touch
- yum模块:用于管理yum软件包,包括安装、升级、删除等操作。 例如,使用yum模块安装一个软件包:
- name: Install a package
yum:
name: httpd
state: present
- service模块:用于管理系统服务,包括启动、停止、重启等操作。 例如,使用service模块启动一个服务:
- name: Start a service
service:
name: httpd
state: started
- copy模块:用于复制文件和目录。 例如,使用copy模块复制一个文件:
- name: Copy a file
copy:
src: /root/hello.txt
dest: /root/world.txt
- template模块:用于生成配置文件,支持使用变量和循环语句等高级功能。 例如,使用template模块生成一个配置文件:
- name: Generate a config file
template:
src: /root/nginx.conf.j2
dest: /etc/nginx/nginx.conf
``
原文地址: https://www.cveoy.top/t/topic/g6VG 著作权归作者所有。请勿转载和采集!