You can use something like:

- slurp:
    path: /some/local/path
  register: some_var
  delegate_to: localhost

Then it would use localhost as the target.

On Mon, Jan 20, 2020 at 10:47 AM Jan Burian <jan.bur...@elostech.cz> wrote:

> Thanks for quick response.
> I understand now, that lookup is templating engine which works only with
> utf8 text.
> I don't need to do `{{ whatever.content|b64decode }}` - decode.
> I need only base64 encode binary file so I can pass the base64 string to
> k8s module.
> slurp would be fine except that slurp fetch binary file from remote host.
> I have file on local host.
>
>
> On Monday, January 20, 2020 at 5:34:46 PM UTC+1, Matt Martz wrote:
>>
>> In short, you cannot send binary data in a module argument.
>>
>> If you can send base64 data instead of binary, you can use the `slurp`
>> module to get the base64 encoded data.  But you won't be able to do `{{
>> whatever.content|b64decode }}` since that would try and produce binary
>> data.  Effectively you cannot send binary data through the templating
>> engine.
>>
>> On Mon, Jan 20, 2020 at 10:26 AM Jan Burian <jan....@elostech.cz> wrote:
>>
>>> Hi,
>>>
>>> I'm trying to read binary file from ansible master (localhost) to use it
>>> in k8s module.
>>>
>>> The task looks like this:
>>>   - name: Create ConfigMap with keytab
>>>     k8s:
>>>       host: "{{ api_host }}"
>>>       api_version: v1
>>>       kind: ConfigMap
>>>       state: present
>>>       definition:
>>>         metadata:
>>>           name: cm-binary-data
>>>           namespace: test-namespace
>>>         binaryData:
>>>           binary-file.bin: "{{ lookup('file', 'files/binary_file.bin')
>>> | b64encode }}"
>>>
>>> So tha vaule of k8s.definition.binaryData.binary-file.bin should be
>>> base64 encoded string.
>>> My goal is to have universal ansible role and in every use there will be
>>> different file - so I can't put there the string directly, instead I will
>>> pass the file as variable to the playbook.
>>>
>>> The problem is that lookup file cannot read binary file - only utf8 text
>>> file.
>>>
>>> Workaround I can now think of is that I can encode base64 file using
>>> shell module and register the result. Then I can read the base64 string
>>> from registered variable.
>>> BUT I have to use shell module which is not recomended way (it is not
>>> best practice) and I'm trying not to use shell module.
>>>
>>> Any tips how to do that without shell module?
>>>
>>> Thanks and Regards
>>> Jan
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to ansible...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/7f923096-1f9c-42be-9a4f-246db57dfd32%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/7f923096-1f9c-42be-9a4f-246db57dfd32%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Matt Martz
>> @sivel
>> sivel.net
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1fbae5b8-3334-45d5-9a83-93528cb9fd6c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1fbae5b8-3334-45d5-9a83-93528cb9fd6c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-1%2BBvU7ZsjTWcKc-WjEZD0qWsLgBs%3DJ4KXnnCN3uJx3g%40mail.gmail.com.

Reply via email to