0

I would like to read a remote file content in an Ansible playbook.

- name: Load spark defaults
  slurp:
    src: /etc/spark/conf/spark-defaults.conf
  register: spark_defaults

- debug:
    msg: "{{ spark_defaults['content'] | b64decode }}"

I have read the documentation of both slurp and fetch and both mention they are intended to get the remote file. But the available parameters does not have the host.

I tried:

- name: Load spark defaults
  slurp:
    src: my.host://etc/spark/conf/spark-defaults.conf
  register: spark_defaults
- name: Load spark defaults
  slurp:
    src: me@my.host://etc/spark/conf/spark-defaults.conf
  register: spark_defaults

but cant seem to get it work. I guess I miss something fundamental and will really appreciate help here.

Noam Shaish
  • 1,613
  • 2
  • 16
  • 37

1 Answers1

0

While writing the question I figure out the answer. I hope it helps others: the secret is to use delegate_to

- name: Load spark defaults
  slurp:
    src: /etc/spark/conf/spark-defaults.conf
  delegate_to: my.host
  remote_user: me
  register: spark_defaults
Noam Shaish
  • 1,613
  • 2
  • 16
  • 37