一、利用循环迭代任务

1️⃣:Ansible支持使用loop关键字对一组项目迭代任务,可以配置循环以利用列表中的各个项目、列表中各个文件的内容、生成的数字序列或更为复杂的结构来重复任务

1、简单循环

1️⃣:简单循环对一组项目迭代任务。loop关键字添加到任务中,将应对其迭代任务的项目列表取为值。循环变量item保存每个迭代过程中使用的值

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: create user
    7. user:
    8. name: "{{ item }}"
    9. state: present
    10. loop:
    11. - zhangsan
    12. - lisi
    13.  
    14. //测试执行play
    15. [root@localhost project]# ansible-playbook playbook.yaml -C
    16.  
    17. PLAY [all] ****************************************************************************************************************************************************************
    18.  
    19. TASK [Gathering Facts] ****************************************************************************************************************************************************
    20. ok: [client.example.com]
    21.  
    22. TASK [create user] ********************************************************************************************************************************************************
    23. changed: [client.example.com] => (item=zhangsan)
    24. changed: [client.example.com] => (item=lisi)
    25.  
    26. PLAY RECAP ****************************************************************************************************************************************************************
    27. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

2️⃣:此外、还可以通过变量给loop提供所使用的的列表

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. vars:
    6. users:
    7. - zhangsan
    8. - lisi
    9. - wangwu
    10. tasks:
    11. - name: create user
    12. user:
    13. name: "{{ item }}"
    14. state: present
    15. loop: "{{ users }}"
    16.  
    17. //执行play
    18. [root@localhost project]# ansible-playbook playbook.yaml -C
    19.  
    20. PLAY [all] ****************************************************************************************************************************************************************
    21.  
    22. TASK [Gathering Facts] ****************************************************************************************************************************************************
    23. ok: [client.example.com]
    24.  
    25. TASK [create user] ********************************************************************************************************************************************************
    26. changed: [client.example.com] => (item=zhangsan)
    27. changed: [client.example.com] => (item=lisi)
    28. changed: [client.example.com] => (item=wangwu)
    29.  
    30. PLAY RECAP ****************************************************************************************************************************************************************
    31. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

2、循环散列或字典列表

1️⃣: loop列表不需要是简单值列表

  • 演示实例:item标识一个循环的项目(任务),item.name和item.group表示item的两个键值(键值可自定义,但必须与loop中的项目匹配)

    1. //查看playbook文件
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: create user
    7. user:
    8. name: "{{ item.name }}"
    9. group: "{{ item.group}}"
    10. state: present
    11. loop:
    12. - name: zhangsan
    13. group: zhangsan
    14. - name: lisi
    15. group: lisi
    16.  
    17. //测试是否可play
    18. [root@localhost project]# ansible-playbook playbook.yaml -C
    19.  
    20. PLAY [all] ****************************************************************************************************************************************************************
    21.  
    22. TASK [Gathering Facts] ****************************************************************************************************************************************************
    23. ok: [client.example.com]
    24.  
    25. TASK [create user] ********************************************************************************************************************************************************
    26. changed: [client.example.com] => (item={'name': 'zhangsan', 'group': 'zhangsan'})
    27. changed: [client.example.com] => (item={'name': 'lisi', 'group': 'lisi'})
    28.  
    29. PLAY RECAP ****************************************************************************************************************************************************************
    30. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

3、将Register变量于Loop一起使用

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: show some user
    7. shell: 'echo this user is {{ item }}'
    8. loop:
    9. - zhangsan
    10. - lisi
    11. - wangwu
    12. register: result
    13.  
    14. - name: show these user
    15. debug:
    16. var: result
    17.  
    18. //测试是否执行play
    19. [root@localhost project]# ansible-playbook playbook.yaml -C
    20.  
    21. PLAY [all] ****************************************************************************************************************************************************************
    22.  
    23. TASK [Gathering Facts] ****************************************************************************************************************************************************
    24. ok: [client.example.com]
    25.  
    26. TASK [show some user] *****************************************************************************************************************************************************
    27. skipping: [client.example.com] => (item=zhangsan)
    28. skipping: [client.example.com] => (item=lisi)
    29. skipping: [client.example.com] => (item=wangwu)
    30.  
    31. TASK [show these user]
    32. ............
    33. "item": "zhangsan",
    34. "msg": "skipped, running in check mode",
    35. "skipped": true
    36. ............
    37. "item": "lisi",
    38. "msg": "skipped, running in check mode",
    39. "skipped": true
    40. .............
    41. "item": "wangwu",
    42. "msg": "skipped, running in check mode",
    43. "skipped": true
    44. .............

1️⃣: 在上面的例子中,results键包含一个列表。在下面,修改了playbook,使第二个任务迭代此列表

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: show some user
    7. shell: 'echo this user is {{ item }}'
    8. loop:
    9. - zhangsan
    10. - lisi
    11. - wangwu
    12. register: magic
    13.  
    14. - name: show these user
    15. debug:
    16. msg: "{{ item.stdout }}"
    17. loop: "{{ magic['results'] }}"
    18.  
    19. //执行play
    20. [root@localhost project]# ansible-playbook playbook.yaml
    21.  
    22. PLAY [all] ****************************************************************************************************************************************************************
    23.  
    24. TASK [Gathering Facts] ****************************************************************************************************************************************************
    25. ok: [client.example.com]
    26.  
    27. TASK [show some user] *****************************************************************************************************************************************************
    28. changed: [client.example.com] => (item=zhangsan)
    29. changed: [client.example.com] => (item=lisi)
    30. changed: [client.example.com] => (item=wangwu)
    31.  
    32. TASK [show these user] ****************************************************************************************************************************************************
    33. ok: [client.example.com] => (item={'cmd': 'echo this user is zhangsan', 'stdout': 'this user is zhangsan', 'stderr': '', 'rc': 0, 'start': '2020-09-03 15:28:50.767109', 'end': '2020-09-03 15:28:50.774188', 'delta': '0:00:00.007079', 'changed': True, 'invocation': {'module_args': {'_raw_params': 'echo this user is zhangsan', '_uses_shell': True, 'warn': True, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}, 'stdout_lines': ['this user is zhangsan'], 'stderr_lines': [], 'failed': False, 'item': 'zhangsan', 'ansible_loop_var': 'item'}) => {
    34. "msg": "this user is zhangsan"
    35. }
    36. ok: [client.example.com] => (item={'cmd': 'echo this user is lisi', 'stdout': 'this user is lisi', 'stderr': '', 'rc': 0, 'start': '2020-09-03 15:28:51.542241', 'end': '2020-09-03 15:28:51.547953', 'delta': '0:00:00.005712', 'changed': True, 'invocation': {'module_args': {'_raw_params': 'echo this user is lisi', '_uses_shell': True, 'warn': True, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}, 'stdout_lines': ['this user is lisi'], 'stderr_lines': [], 'failed': False, 'item': 'lisi', 'ansible_loop_var': 'item'}) => {
    37. "msg": "this user is lisi"
    38. }
    39. ok: [client.example.com] => (item={'cmd': 'echo this user is wangwu', 'stdout': 'this user is wangwu', 'stderr': '', 'rc': 0, 'start': '2020-09-03 15:28:52.292883', 'end': '2020-09-03 15:28:52.298768', 'delta': '0:00:00.005885', 'changed': True, 'invocation': {'module_args': {'_raw_params': 'echo this user is wangwu', '_uses_shell': True, 'warn': True, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}, 'stdout_lines': ['this user is wangwu'], 'stderr_lines': [], 'failed': False, 'item': 'wangwu', 'ansible_loop_var': 'item'}) => {
    40. "msg": "this user is wangwu"
    41. }
    42.  
    43. PLAY RECAP ****************************************************************************************************************************************************************
    44. client.example.com : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

二、有条件的运行任务

Ansible可使用conditionals在符合特定条件时执行任务或play。例如,可以利用一个条件在Ansible安装或配置服务前确定受管主机上的可用内存

1、条件任务语法

1️⃣:when语句用于有条件地运行任务;它取要测试的条件为值。如果条件满足,则运行任务。如果条件不满足,则跳过任务

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. vars:
    6. package: True
    7. tasks:
    8. - name: install httpd
    9. yum:
    10. name: httpd
    11. state: installed
    12. when: package
    13.  
    14. //测试执行play
    15. [root@localhost project]# ansible-playbook playbook.yaml
    16.  
    17. PLAY [all] ****************************************************************************************************************************************************************
    18.  
    19. TASK [Gathering Facts] ****************************************************************************************************************************************************
    20. ok: [client.example.com]
    21.  
    22. TASK [install httpd] ******************************************************************************************************************************************************
    23. changed: [client.example.com]
    24.  
    25. PLAY RECAP ****************************************************************************************************************************************************************
    26. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

2️⃣:处理条件时可使用的一些运算示例

操作 示例
等于(值为字符串) ansible_machine == "x86_64"
等于(值为数字) max_memory == 512
小于 min_memory < 128
大于 min_memory > 256
小于等于 min_memory <= 256
大于等于 min_memory >= 512
不等于 min_memory != 512
变量存在 min_memory is defined
变量不存在 min_memory is not defined
布尔变量是True。1、True或yes的求值为True memory_available
布尔变量是False。0、False或no的求值为False not memory_available
第一个变量的值存在,作为第二个变量的列表中的值 ansible_distribution in supported_distros
  • 演示实例一:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. vars:
    6. package: httpd
    7. tasks:
    8. - name: install {{ package }}
    9. yum:
    10. name: "{{ package }}"
    11. state: present
    12. when: package is defined
    13.  
    14. //执行play
    15. [root@localhost project]# ansible-playbook playbook.yaml
    16.  
    17. PLAY [all] ****************************************************************************************************************************************************************
    18.  
    19. TASK [Gathering Facts] ****************************************************************************************************************************************************
    20. ok: [client.example.com]
    21.  
    22. TASK [install httpd] ******************************************************************************************************************************************************
    23. changed: [client.example.com]
    24.  
    25. PLAY RECAP ****************************************************************************************************************************************************************
    26. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  • 演示实例二:第一个变量的值存在(一般是事实),且作为第二个变量列表中的值

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. vars:
    6. version:
    7. - RedHat
    8. - CentOS
    9. tasks:
    10. - name: install httpd
    11. yum:
    12. name: httpd
    13. state: present
    14. when: ansible_facts['distribution'] in version //ansible_facts['distribution']该变量的值与versionversion中的值匹配
    15.  
    16. //执行play
    17. [root@localhost project]# ansible-playbook playbook.yaml
    18.  
    19. PLAY [all] ****************************************************************************************************************************************************************
    20.  
    21. TASK [Gathering Facts] ****************************************************************************************************************************************************
    22. ok: [client.example.com]
    23.  
    24. TASK [install httpd] ******************************************************************************************************************************************************
    25. changed: [client.example.com]
    26.  
    27. PLAY RECAP ****************************************************************************************************************************************************************
    28. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  • 演示实例三:(判断大小)

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. vars:
    6. number: 800
    7. tasks:
    8. - name: install httpd
    9. yum:
    10. name: httpd
    11. state: present
    12. when: number >= 800
    13.  
    14. //执行play
    15. [root@localhost project]# ansible-playbook playbook.yaml
    16.  
    17. PLAY [all] ****************************************************************************************************************************************************************
    18.  
    19. TASK [Gathering Facts] ****************************************************************************************************************************************************
    20. ok: [client.example.com]
    21.  
    22. TASK [install httpd] ******************************************************************************************************************************************************
    23. changed: [client.example.com]
    24.  
    25. PLAY RECAP ****************************************************************************************************************************************************************
    26. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

2、测试多个条件

1️⃣:一个when语句可用于评估多个条件:使用andor关键字组合条件,并使用括号分组条件

2️⃣:使用and语句运算时,两个条件必须为真,才能满足整个条件语句

  • 演示实例一:and 语句第一种写法

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. when: ansible_facts['distribution_version'] == "8.1" and ansible_facts['distribution'] == "RedHat"
    11.  
    12. //执行play
    13. [root@localhost project]# ansible-playbook playbook.yaml
    14.  
    15. PLAY [all] ****************************************************************************************************************************************************************
    16.  
    17. TASK [Gathering Facts] ****************************************************************************************************************************************************
    18. ok: [client.example.com]
    19.  
    20. TASK [install httpd] ******************************************************************************************************************************************************
    21. changed: [client.example.com]
    22.  
    23. PLAY RECAP ****************************************************************************************************************************************************************
    24. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  • 演示实例二:and 语句第二种写法

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. when:
    11. - ansible_facts['distribution_version'] == "8.1"
    12. - ansible_facts['distribution'] == "RedHat"
    13.  
    14. //执行play
    15. [root@localhost project]# ansible-playbook playbook.yaml
    16.  
    17. PLAY [all] ****************************************************************************************************************************************************************
    18.  
    19. TASK [Gathering Facts] ****************************************************************************************************************************************************
    20. ok: [client.example.com]
    21.  
    22. TASK [install httpd] ******************************************************************************************************************************************************
    23. changed: [client.example.com]
    24.  
    25. PLAY RECAP ****************************************************************************************************************************************************************
    26. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  • 演示实例三:and 语句第三中写法

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. when:
    11. ( ansible_facts['distribution_version'] == "8.1" )
    12. and
    13. ( ansible_facts['distribution'] == "RedHat" )
    14.  
    15. //执行play
    16. [root@localhost project]# ansible-playbook playbook.yaml
    17.  
    18. PLAY [all] ****************************************************************************************************************************************************************
    19.  
    20. TASK [Gathering Facts] ****************************************************************************************************************************************************
    21. ok: [client.example.com]
    22.  
    23. TASK [install httpd] ******************************************************************************************************************************************************
    24. changed: [client.example.com]
    25.  
    26. PLAY RECAP ****************************************************************************************************************************************************************
    27. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

3️⃣:使用or语句时,其中任一条件为真时,就能满足条件语句

  • 演示实例一:or 语句第一种写法

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. when: ansible_facts['distribution'] == "RedHat" or ansible_facts['distribution_version'] == "7.9"
    11.  
    12. //执行play
    13. [root@localhost project]# ansible-playbook playbook.yaml
    14.  
    15. PLAY [all] ****************************************************************************************************************************************************************
    16.  
    17. TASK [Gathering Facts] ****************************************************************************************************************************************************
    18. ok: [client.example.com]
    19.  
    20. TASK [install httpd] ******************************************************************************************************************************************************
    21. changed: [client.example.com]
    22.  
    23. PLAY RECAP ****************************************************************************************************************************************************************
    24. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    25. //我当前使用的是RHEL8.1版本
  • 演示实例二:or 语句第二种写法

    1. [root@localhost project]# cat playbook.yaml
    2. ---
    3. - hosts: all
    4. tasks:
    5. - name: install httpd
    6. yum:
    7. name: httpd
    8. state: present
    9. when: > //这里可以加,也可以不加;>:是允许下面的变量可以换行写
    10. ( ansible_facts['distribution'] == "RedHat" )
    11. or
    12. ( ansible_facts['distribution_version'] == "7.9 )"
    13.  
    14. //执行play
    15. [root@localhost project]# ansible-playbook playbook.yaml
    16.  
    17. PLAY [all] ****************************************************************************************************************************************************************
    18.  
    19. TASK [Gathering Facts] ****************************************************************************************************************************************************
    20. ok: [client.example.com]
    21.  
    22. TASK [install httpd] ******************************************************************************************************************************************************
    23. changed: [client.example.com]
    24.  
    25. PLAY RECAP ****************************************************************************************************************************************************************
    26. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  • 演示实例三:or 语句的第三种写法(与and语句嵌套使用)

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. when:
    11. ( ansible_facts['distribution'] == "RedHat" and ansible_facts['kernel'] == "4.18.0-147.el8.x86_64" )
    12. or
    13. ( ansible_facts['distribution_version'] == "7.9" and ansible_facts['distribution_major_version'] == "7" )
    14.  
    15. //执行play
    16. [root@localhost project]# ansible-playbook playbook.yaml
    17.  
    18. PLAY [all] ****************************************************************************************************************************************************************
    19.  
    20. TASK [Gathering Facts] ****************************************************************************************************************************************************
    21. ok: [client.example.com]
    22.  
    23. TASK [install httpd] ******************************************************************************************************************************************************
    24. changed: [client.example.com]
    25.  
    26. PLAY RECAP ****************************************************************************************************************************************************************
    27. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

三、组合循环和有条件任务

1、使用Loop和When组合使用

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. loop: "{{ ansible_facts['mounts'] }}"
    11. when:
    12. - item.mount == "/"
    13. - item.size_available > 50000000000
    14.  
    15. //执行paly
    16. [root@localhost project]# ansible-playbook playbook.yaml
    17.  
    18. PLAY [all] ****************************************************************************************************************************************************************
    19.  
    20. TASK [Gathering Facts] ****************************************************************************************************************************************************
    21. ok: [client.example.com]
    22.  
    23. TASK [install httpd] ******************************************************************************************************************************************************
    24. changed: [client.example.com] => (item={'mount': '/', 'device': '/dev/mapper/rhel-root', 'fstype': 'xfs', 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'size_total': 53660876800, 'size_available': 51805659136, 'block_size': 4096, 'block_total': 13100800, 'block_available': 12647866, 'block_used': 452934, 'inode_total': 26214400, 'inode_available': 26178405, 'inode_used': 35995, 'uuid': '6a525cf5-3f23-4639-81cb-04fcdb764eb6'})
    25. skipping: [client.example.com] => (item={'mount': '/home', 'device': '/dev/mapper/rhel-home', 'fstype': 'xfs', 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'size_total': 28922376192, 'size_available': 28686655488, 'block_size': 4096, 'block_total': 7061127, 'block_available': 7003578, 'block_used': 57549, 'inode_total': 14129152, 'inode_available': 14129137, 'inode_used': 15, 'uuid': '2840f839-89b2-4717-b1d0-c74c46d05019'})
    26. skipping: [client.example.com] => (item={'mount': '/boot', 'device': '/dev/nvme0n1p1', 'fstype': 'xfs', 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'size_total': 1063256064, 'size_available': 882565120, 'block_size': 4096, 'block_total': 259584, 'block_available': 215470, 'block_used': 44114, 'inode_total': 524288, 'inode_available': 523987, 'inode_used': 301, 'uuid': '234365dc-2262-452e-9cbb-a6acfde04385'})
    27. skipping: [client.example.com] => (item={'mount': '/mnt', 'device': '/dev/sr0', 'fstype': 'iso9660', 'options': 'ro,relatime,nojoliet,check=s,map=n,blocksize=2048', 'size_total': 7851202560, 'size_available': 0, 'block_size': 2048, 'block_total': 3833595, 'block_available': 0, 'block_used': 3833595, 'inode_total': 0, 'inode_available': 0, 'inode_used': 0, 'uuid': '2019-10-15-13-34-03-00'})
    28.  
    29. PLAY RECAP ****************************************************************************************************************************************************************
    30. client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

2、使用Register和When组合使用

  • 演示实例:

    1. //查看playbook
    2. [root@localhost project]# cat playbook.yaml
    3. ---
    4. - hosts: all
    5. tasks:
    6. - name: install httpd
    7. yum:
    8. name: httpd
    9. state: present
    10. ignore_errors: yes //在运行时,如果出现错误且命令失败,将不会停止,继续执行其他的命令
    11. register: result //将安装成功后的结果注册到result变量中
    12.  
    13. - name: start httpd
    14. service:
    15. name: httpd
    16. state: started
    17. when: result.rc == 0 //在该变量中匹配到返回值rc=0执行该命令
    18.  
    19. //执行play
    20. [root@localhost project]# ansible-playbook playbook.yaml
    21.  
    22. PLAY [all] ****************************************************************************************************************************************************************
    23.  
    24. TASK [Gathering Facts] ****************************************************************************************************************************************************
    25. ok: [client.example.com]
    26.  
    27. TASK [install httpd] ******************************************************************************************************************************************************
    28. changed: [client.example.com]
    29.  
    30. TASK [start httpd] ********************************************************************************************************************************************************
    31. changed: [client.example.com]
    32.  
    33. PLAY RECAP ****************************************************************************************************************************************************************
    34. client.example.com : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

下一篇实施处理程序

Ansible_编写循环和条件任务的更多相关文章

  1. python Django教程 之模板渲染、循环、条件判断、常用的标签、过滤器

    python3.5 manage.py runserver python Django教程 之模板渲染.循环.条件判断.常用的标签.过滤器 一.Django模板渲染模板 1. 创建一个 zqxt_tm ...

  2. Java循环和条件

    下列程序的输出结果是什么? 1.Java循环和条件 /** * @Title:IuputData.java * @Package:com.you.data * @Description:TODO * ...

  3. 第二天:python的函 数、循环和条件、类

    https://uqer.io/community/share/54c8af17f9f06c276f651a54 第一天学习了Python的基本操作,以及几种主要的容器类型,今天学习python的函数 ...

  4. Java 控制语句:循环、条件判断

    基础很重要,基础很重要,基础很重要.重要的事情说三遍,. 程序设计中的控制语句主要有三种:顺序.分支和循环.我们每天写的代码,除了业务相关,里面会包含大量的控制语句.但是控制语句的基本使用,是否有些坑 ...

  5. javascript面向对象编程笔记(基本数据类型,数组,循环及条件表达式)

    javascript面向对象编程指南 最近在看这本书,以下是我的笔记,仅供参考. 第二章 基本数据类型.数组.循环及条件表达式 2.1 变量 区分大小写 2.3 基本数据类型 数字:包括浮点数与整数 ...

  6. SQL中循环和条件语句

    .if语句使用示例: declare @a int begin print @a end else begin print 'no' end .while语句使用示例: declare @i int ...

  7. Ansible系列(六):循环和条件判断

    本文目录:1. 循环 1.1 with_items迭代列表 1.2 with_dict迭代字典项 1.3 with_fileglob迭代文件 1.4 with_lines迭代行 1.5 with_ne ...

  8. PHP和JS在循环、条件判断中的不同之处

    一.条件判断: php中算  false 的情况 1. boolean:false 2. 整形:0 3.浮点型:0 4.字符串:"" "0"(其他都对) 5.空 ...

  9. SqlServer中循环和条件语句

    if语句使用示例 declare @a int              set @a=12              if @a>100                 begin      ...

随机推荐

  1. [Fundamental of Power Electronics]-PART II-8. 变换器传递函数-8.3 阻抗和传递函数图形的构建

    8.3 阻抗和传递函数图形的构建 通常,我们可以通过观察来绘制近似的bode图,这样没有大量混乱的代数和不可避免的有关代数错误.使用这种方法可以对电路运行有较好的了解.在各种频率下哪些元件主导电路的响 ...

  2. java面试-JVM常用的基本配置参数有哪些?

    1.-Xms 初始大小内存,默认为物理内存 1/64,等价于 -XX:InitialHeapSize 2.-Xmx 最大分配内存,默认为物理内存的 1/4,等价于 -XX:MaxHeapSize 3. ...

  3. 一文彻底搞定Hystrix!

    前言 Netflix Hystrix断路器是什么? Netflix Hystrix是SOA/微服务架构中提供服务隔离.熔断.降级机制的工具/框架.Netflix Hystrix是断路器的一种实现,用于 ...

  4. DDD实战让中台和微服务的落地如虎添翼

    微服务到底怎么拆分和设计才算合理,拆多小才叫微服务?有没有好的方法来指导微服务和中台的设计呢? 深入DDD的核心知识体系与设计思想,带你掌握一套完整而系统的基于DDD的微服务拆分与设计方法,助力落地边 ...

  5. 用递归求出n的全排列

    1 include<cstdio> 2 const int maxn = 11; 3 int n,p[maxn], hashTable[maxn] = { false };//hashta ...

  6. 浅谈 Fresco 框架结构

    在前面的文章 Fresco 源码分析 -- 图片加载流程 里面详细说明了图片加载的整个流程,但是除了理解源码之外,对于源码的框架层面的设计也是需要去了解的,不能只是简单的读源码,好的源码的框架设计也是 ...

  7. 深入学习spring cloud gateway 限流熔断

    前言 Spring Cloud Gateway 目前,Spring Cloud Gateway是仅次于Spring Cloud Netflix的第二个最受欢迎的Spring Cloud项目(就GitH ...

  8. QT程序发布

    1.新建一个脚本文件,后缀为.bat 2.查看自己qt的windeployqt.exe路径,一般在QT安装的bin目录,而且脚本程序中需要去掉其后缀, 前面部分是windeployqt.exe的路径以 ...

  9. shell脚本 4 函数与正则

    shell函数 shell中允许将一组命令集合或语句形成一段可用代码,这些代码块称为shell函数.给这段代码起个名字称为函数名,后续可以直接调用该段代码. 格式 func() {   #指定函数名 ...

  10. Floyd算法C++实现与模板题应用

    简介 Floyd算法算是最简单的算法,没有之一. 其状态转移方程如下map[i , j] =min{ map[i , k] + map[k , j] , map[i , j] }: map[i , j ...