帮我写一份关于Ansible使用yum安装httpd的playbook
-
name: Install httpd using yum hosts: all become: true
tasks:
-
name: Install httpd package yum: name: httpd state: present
-
name: Start httpd service service: name: httpd state: started enabled: true
-
name: Create index.html file copy: content: "
Welcome to my website!
" dest: /var/www/html/index.html -
name: Set SELinux context for index.html sefcontext: target: /var/www/html/index.html setype: httpd_sys_content_t
-
name: Restart httpd service service: name: httpd state: restarted
-
说明:
- 该playbook的目的是在所有主机上安装httpd并启动服务,然后在/var/www/html/目录下创建一个index.html文件,最后重启httpd服务。
- become: true表示使用sudo权限执行任务。
- yum模块用于安装httpd软件包。
- service模块用于启动和重启httpd服务。
- copy模块用于创建index.html文件并将其复制到/var/www/html/目录下。
- sefcontext模块用于为index.html文件设置SELinux上下文。
- 该playbook可用于在CentOS、Red Hat等基于RPM的Linux系统上安装httpd。
原文地址: https://www.cveoy.top/t/topic/bCZ9 著作权归作者所有。请勿转载和采集!