---
- name: letsencrypt
  hosts: supermaster
  become: yes
  vars_files:
    - var/domains.yml
  tasks:
    # - name: add domain to nginx with j2 block
    #   template:
    #     src: template/nginx-server-block.j2
    #     dest: /tmp/new-nginx-server-block.{{item.server_name}}.conf
    #   with_items:
    #     - "{{ newDomains }}"
    
    # - name: append /tmp/new-nginx-server-block.conf to specific conf
    #   shell: |
    #     cat /tmp/new-nginx-server-block.{{item.server_name}}.conf >> /etc/nginx/sites-available/{{ item.conf_file }}
    #     rm -rf /tmp/new-nginx-server-block.{{item.server_name}}.conf
    #   with_items:
    #     - "{{ newDomains }}"

    - name: encrypt all domains 
      expect:
        command: certbot --nginx -d "{{ item.server_name }}"
        responses:
          Question:
            - 2
            - 2
      with_items:
        - "{{ newDomains }}"

    