• 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


说明:

  1. 该playbook的目的是在所有主机上安装httpd并启动服务,然后在/var/www/html/目录下创建一个index.html文件,最后重启httpd服务。
  2. become: true表示使用sudo权限执行任务。
  3. yum模块用于安装httpd软件包。
  4. service模块用于启动和重启httpd服务。
  5. copy模块用于创建index.html文件并将其复制到/var/www/html/目录下。
  6. sefcontext模块用于为index.html文件设置SELinux上下文。
  7. 该playbook可用于在CentOS、Red Hat等基于RPM的Linux系统上安装httpd。
帮我写一份关于Ansible使用yum安装httpd的playbook

原文地址: https://www.cveoy.top/t/topic/bCZ9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录