ansible 循环

安装通用软件

---

- name: ansible playbook
  hosts: all
  remote_user: root
  become: yes
  vars:
	user_name: 'test'
  var_files:
  
  tasks:
	- name: 常用工具
	  yum:
		name: '{{ item }}'
		state: latest
	  with_items:
		- tree
		- zip
	  tags:
		- common

hash 类型

---

- name: ansible playbook
  hosts: all
  remote_user: root
  become: yes
  vars:
	user_name: 'test'
  var_files:
  
  tasks:
	- name: 常用工具
	  yum:
		name: '{{ item.name }}'
		state: '{{ item.state }}'
		state: latest
	  with_items:
		- {name: tree,  state: latest}
		- {name: zip, state: latest}
	  tags:
		- common