20/11/2024

Ansible – 8 Ansible Loops

1. Basit loop

- name: Enable Service
      service:
        name: "{{ item }}"
        state: started
        enabled: true
      loop:
        - httpd
        - firewalld

2. Biraz daha karmasik loop

Bir variable list üzerinde loop yapmak istersek.

- name: Looping
  hosts: linux_hosts
  become: true
  vars:
    userlist:
      - user01
      - user02
      - user03
  tasks:
    - name: Create users
      user:
        name: "{{ item }}"
      with_list: "{{ userlist }}"

With_list ile verilen listedeki herbir variable icin bu task calisacak her bir node da.