thefinn93 / ansible-letsencrypt

An ansible role to generate TLS certificates and get them signed by Let's Encrypt
GNU General Public License v3.0
440 stars 122 forks source link

Older Ansible not supported any more? Getting "'ssl_certificate' is undefined" #66

Open centic9 opened 6 years ago

centic9 commented 6 years ago

Trying to run the current version of this role from Galaxy, I get the following when using Ansible 2.0.0 (the latest on base Ubuntu Xenial):

TASK [../../roles/thefinn93.letsencrypt : Create directory for `ssl_certificate` and `ssl_certificate_key`] ***
task path: /opt/svn/Ansible/roles/thefinn93.letsencrypt/tasks/main.yml:86
fatal: [vserver]: FAILED! => {"failed": true, "msg": "ERROR! 'ssl_certificate' is undefined"}

It looks like the with_items is not supported with "when"?

  - name: Create directory for `ssl_certificate` and `ssl_certificate_key`
    file:
      path: '{{ item }}'
      state: directory
      recurse: yes
    when: ssl_certificate is defined and ssl_certificate_key is defined
    with_items:
      - "{{ ssl_certificate|dirname }}"
      - "{{ ssl_certificate_key|dirname }}"

If I change that to the following it seems to work:


  - name: Create directory for `ssl_certificate` and `ssl_certificate_key`
    file:
      path: "{{ ssl_certificate_key|dirname }}"
      state: directory
      recurse: yes
    when: ssl_certificate is defined and ssl_certificate_key is defined

  - name: Create directory for `ssl_certificate` and `ssl_certificate_key`
    file:
      path: "{{ ssl_certificate|dirname }}"
      state: directory
      recurse: yes
    when: ssl_certificate is defined and ssl_certificate_key is defined

  - name: Symlink certificates to `ssl_certificate` and `ssl_certificate_key`
    file:
      src: /etc/letsencrypt/live/{{ letsencrypt_cert_domains[0] }}/fullchain.pem
      dest: "{{ssl_certificate}}"
      state: link
    when: ssl_certificate is defined and ssl_certificate_key is defined

  - name: Symlink certificates to `ssl_certificate` and `ssl_certificate_key`
    file:
      src: /etc/letsencrypt/live/{{ letsencrypt_cert_domains[0] }}/privkey.pem
      dest: "{{ssl_certificate_key}}"
      state: link
    when: ssl_certificate is defined and ssl_certificate_key is defined