Reputation: 157
I am trying to create a playbook where the created certs should be added as variable to create templates from it. The created certs are of *.pem format and resides in ansible localhost. I need to cat these files and load the contents as variable like x_cert, y_key etc. Tried the shell:cat and register method which works fine, but since the number of certs are high, this method is not recommended and Im searching for any module based method.
Tried lookup and slurp, slurp works only on remote host and I want that to work in localhost. the lookup Im using does not work. Not sure.
Can anybody shed some light on this.
Slurp code, which works in remote host
#- slurp:
# src: "{{ x_secrets_path }}/certs/test/x-cert.pem"
# register: x_cert
lookup code which is not working so far
- name: load cert
delegate_to: localhost
adminsrv_cert= "{{ lookup('file', '{{ x_secrets_path }}/certs/test/x-cert.pem') }}"
Upvotes: 0
Views: 709
Reputation: 157
Below action worked for me. but still the registered variable contains all the output, which includes extra characters etc. I need only the content of the file.
- slurp:
src: "{{ certs_path }}/certs/test/x-cert.pem"
register: x_cert
delegate_to: localhost
- slurp:
src: "{{ certs_path }}/certs/test/x-key.pem"
register: x_key
delegate_to: localhost
Upvotes: 0