摘要:
- hosts: all tasks: - name: debug debug: msg: "{{ item.key }} 的名字叫 {{ item.value.name }}" with_dict: - user01: name: zhangsan age: 30 - user02: name: 阅读全文
摘要:
with_list 不展开循环嵌套的列表。功能类似于 for i in zip([1,2,3],['a','b','c']): print(i) - hosts: all tasks: - name: debug debug: msg: "{{ item }}" with_list - ["a"," 阅读全文
摘要:
在tasks 中注册变量set_fact,该变量可以跨tasks调用 - hosts: 127.0.0.1 tasks: - set_fact: var: "value" - name: debug: msg: "{{ var }}" - hosts: 127.0.0.1 tasks: - name 阅读全文
摘要:
可以通过 ansible 127.0.0.1 -m setup查看支持的内置变量 - hosts: 127.0.0.1 tasks: - name: debug debug: msg: "hostname: {{ ansible_fqdn }} ip: {{ ansible_default_ipv4 阅读全文
摘要:
每一个task 执行后都有一些返回信息我们可以通过 register 把这些返回信息赋值给变量 - hosts: 127.0.0.1 tasks: - name: mkdir file: path: /tmp/1 state: directory owner: root register: resu 阅读全文
摘要:
示例1 - hosts: 127.0.0.1 vars_prompt: - name: host prompt: "please input your hostip" - name: port prompt: "please input your port" tasks: - name: debug 阅读全文
摘要:
vars_files 可以把var定义的变量分离出来方便修改和复用 - hosts: 127.0.0.1 vars_files: - ./var1.yaml tasks: - name: debug debug: msg: http://{{ bind.ip }}:{{ bind.port }} # 阅读全文
摘要:
支持 字典格式、列表格式。定义和引用完全兼容python格式 {"ip": "127.0.0.1","port": "8000"} [{"ip": "127.0.0.1"},{"port": "8000"}] ["bind":{"ip": "127.0.0.1"},{"port": "8000"}] 阅读全文
摘要:
tags 可以给tasks打标签,之后按照标签有选择的执行任务 - hosts: 127.0.0.1 tasks: - name: mkdir tags: - mkdir1 file: path: /tmp/testdir/1 state: directory recurse: yes owner: 阅读全文
摘要:
第一种类型 - hosts: 127.0.0.1 tasks: - name: mkdir file: path: /tmp/testdir/1 state: directory recurse: yes owner: test - name: touch file: path: /tmp/test 阅读全文