ansible-playbook 配合yml文件,实现批量功能

一、copy功能

yml文件:

---

- name: configure copy local file to remote_host

  hosts: all

  tasks:

  - name: copy yum config file

    copy:

    src: files/centos7.repo

    dest: /etc/yum.repos.d/

执行文件    ansible-playbook copy.yml

二、安装软件,启动软件,我们已安装httpd,php,php-mysql为例

yml文件:

---

- name: configure web server

  hosts: webserver

  tasks:

  - name: install web app

    yum:

      name: "{{item}}"

      state: present

    with_items:

       - httpd

       - php

       - php-mysql

  - name: configure web app

    service:

      name: httpd

      state: started

      enabled: true

执行命令   ansibl-playbook lamp.yml

发布了73 篇原创文章 · 获赞 4 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_27592485/article/details/103188066
今日推荐