-2

I am trying to modify and use this httpd ansible role https://github.com/CentOS/ansible-role-httpd

I'm facing an issue with pki-tls.yml

This piece of code will reproduce the issue I am facing.

---
- name: Copy certificates
  hosts: myhost.domain.com
  remote_user: user
  become: yes

  vars:
    httpd_vhost_shared_list:
      - name: emacs
        fqdn: domain.com
        path: /var/www/emacs
        acl:
          - 10.10.40.0/24
    pkistore: /home/user/certificates

  tasks:
    - name: Debug
      debug:
        var: httpd_vhost_shared_list

    - name: TLS certs
      copy:
        src: "{{ pkistore }}/{{ item.name }}"
        dest: "/etc/pki/tls/certs/{{ item.name }}"
      with_items:
        - "{{ httpd_vhost_shared_list }}.crt"
        - "{{ httpd_vhost_shared_list }}-CAChain.crt"

    - name: TLS key
      copy:
        src: "{{ pkistore }}/{{ item.name }}"
        dest: "/etc/pki/tls/private/{{ item.name }}"
      with_items:
        - "{{ httpd_vhost_shared_list }}.key"

When I run my playbook, I get the following error:

The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeT ext object' has no attribute 'name'

However the variable is defined. How would one do to access name in variable httpd_vhost_shared_list?

Any feedback is welcome.

gnuforever
  • 11
  • 2

1 Answers1

0

In the meantime, I figured out it is simple to split the play "TLS certs" in 2 plays. One for the server certificate and another one for chain certificate.

    - name: TLS certificate
      copy:
        src: "{{ pkistore }}/{{ item.name }}.crt"
        dest: "/etc/pki/tls/certs/{{ item.name }}.crt"
      with_items:
        - "{{ httpd_vhost_shared_list }}"

    - name: TLS chain
      copy:
        src: "{{ pkistore }}/{{ item.name }}-CAChain.crt"
        dest: "/etc/pki/tls/certs/{{ item.name }}-CAChain.crt"
      with_items:
        - "{{ httpd_vhost_shared_list }}"

    - name: TLS key
      copy:
        src: "{{ pkistore }}/{{ item.name }}.key"
        dest: "/etc/pki/tls/private/{{ item.name }}.key"
      with_items:
        - "{{ httpd_vhost_shared_list }}"
gnuforever
  • 11
  • 2