#值为纯量类型时:tasks:-name:模块名:参数1={{item}}with_items:-值1#纵向格式:-值2...tasks:-name:模块名:参数1={{item}}with_items:["值1","值2",...]#横向格式#先使用vars定义循环取值列表,再用with_items引用vars的变量vars:-变量1:-值1#纵向格式-值2...-变量2:["值1","值2",......
1、with_items with_items是playbooks中最基本也是最常用的循环语句: tasks: - name:Secure config files file: path=/etc/` item ` mode=0600 owner=root group=root with_items: - my.cnf - shadow - fstab 1. 2. 3. 4. 5. 6. 7. 上面例子表示,创建三个文件分别为my.cnf、shadow、fstab 也可以...
1. with_items -hosts:testvars:data:-user0-user1-user2tasks:-name:"with_items"debug:msg:"{{ item }}"with_items:"{{ data }}" 2. with_nested tasks: - name:debugloopsdebug: msg="name is {{ item[0] }} vaule is {{ item[1] }} num is {{ item[2] }}"with_nested: - ['a...
1. with_items - hosts: test vars: data: - user0 - user1 - user2 tasks: - name: "with_items" debug: msg: "{{ item }}" with_items: "{{ data }}" 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 2. with_nested tasks: - name: debug loops debug: msg="name is {{ item[0...
在Ansible Playbook中定义一个循环,可以使用with_items关键字来指定循环的对象。例如: 代码语言:txt 复制 - name: Loop through YAML hosts: localhost tasks: - name: Read YAML file include_vars: file: my_vars.yaml name: my_vars - name: Loop through YAML keys ...
with_items: - pcre - pcre-devel - nginxPS:{{ item }} 定义变量 with_items 是 python list 数据结构,task会循环读取list里面的值。key的名称是item。 - pcre - pcre-devel - nginx 如果其它软件包,可将软件包名称依次写在下面。 批量安装
-name:test when conditionhosts:localhostgather_facts:novars:seq:-1-2-3-4tasks:-name:test loop and whendebug:msg:"{{ item }}"with_items:"{{ seq }}"when:item >=3 inventory 编写好playbook之后,执行命令需要指明inventory(如果不指明,就使用默认的hosts文件。) ...
with_items 数据结构对应的是python或是yaml中的列表,每个列表项也可以是字典,每次循环到的当前列表项 使用item来引用. 1.3 示例1: # standard loop name: stanard loop remote_user: root hosts: tomcat tasks: name: loop list debug: msg={{ item }} ...
一台机器可以这么做,如果是集群呢?每一台都要这么做。假如我们管理了几百台机器,突然有一天公司要求...
{item.value}}"with_items:- {key:"no1",value:"val1"}- {key:"no2",value:"val2"}-name:Loop字典循环debug:msg="{{item.name}} --> {{item.group}}"loop:- {name:"no1",group:"val1"}- {name:"no2",group:"val2"}-name:testloops 嵌套循环 2个列表debug:msg="{{item[0]}}--{...