-2

I want to pass some rsa public keys to ansible roles from ansible playbook, however, I find that ansible can't pass varibles when using lookup.

---
- hosts: gateway
  vars: 
    keys:
      - "{{ lookup('file', './files/rsa_pubs/sake1.pub') }}"
      - "{{ lookup('file', './files/rsa_pubs/sake2.pub') }}"
  tasks:
    - name: Set gateway rsa public file.
      import_role: 
        name: ssh_rsa_setting
      vars:
        # rsa_pub_keys:
        #   - "{{ lookup('file', './files/rsa_pubs/sake1.pub') }}"
        #   - "{{ lookup('file', './files/rsa_pubs/sake2.pub') }}"
        rsa_pub_keys: keys

The commneted code failed while using varible "keys" to pass the rsa keys seems fine. I've tried to use "include_role" instead "import_role", nothing changes. I want to know why and how to properly pass the list varibles to roles.

Thanks in advance.

sake
  • 387
  • 4
  • 12
  • 1
    `rsa_pub_keys: keys` => `rsa_pub_keys: "{{ keys }}"` – Zeitounator Jul 17 '20 at 07:05
  • @Zeitounator Thank you. It help me understand "{{}}". Thanks a lot! – sake Jul 17 '20 at 07:23
  • 1
    This is kikd of the base of using jinja2 inside ansible you should get familiar with before going any further: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#using-variables-with-jinja2 – Zeitounator Jul 17 '20 at 07:27

1 Answers1

-1

As @Zeitounator suggest, "{{}}" should be used!

sake
  • 387
  • 4
  • 12