ansible之with_items

with_items个人理解就像是shell里面的循环,可以循环操作

简单案例一:

多个变量

- name: installpakger
  yum: name={{ item }} state=latest    ##安装依赖包
  with_items:
    - openssl-devel
    - pcre-devel
    - gcc

简单案例二:

k/v类型

  - hosts: CentOS-7-4
    gather_facts: false
    tasks:
      - name: copy files
        copy:
          src: "{{ item.src }}"
          dest: "{{ item.dest }}"
        with_items:
          - { src: "/home/ansible/copy.yml", dest: "/home/copy.yml" }

你可能感兴趣的:(ansible之with_items)