---

- name: configure servers
  hosts: all
  become: true
  gather_facts: false
  tasks:
    - include_vars: "vars.yml"

    - name: create the user
      user:
        name: "{{ user_to_add }}"
        state: present

    - name: change the hostname
      hostname: 
        name: "{{ hostname }}"

    - name: Create the dirs
      file:
        name: "{{ item.d }}"
        state: directory
      with_items:
        - "{{ dirs_to_create }}"
    
    - name: Create the files
      file:
        name: "{{ item.filename }}"
        state: touch
      with_items:
        - "{{ dirs_to_create }}"

    - name: register the vars
      shell: "ls  {{ item }} | wc -l "
      ignore_errors: yes 
      loop: "{{ dirs_to_count }}"
      register: "var"

    - name: print the registered variables
      debug:  
        msg: "There are {{ item.stdout }} files in the directory"
      loop: "{{ var.results }}"
