Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active August 1, 2018 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/3902607dddac246ca15395b5aedcc2fb to your computer and use it in GitHub Desktop.
Save YumaInaura/3902607dddac246ca15395b5aedcc2fb to your computer and use it in GitHub Desktop.
Ansible — How to remote machine file body? ( Slurp module VS Shell module cat )
Example Text
PLAY [example] ****************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************
ok: [localhost]
TASK [copy] *******************************************************************************************************************************
ok: [localhost]
TASK [slurp file] *************************************************************************************************************************
ok: [localhost]
TASK [echo file body] *********************************************************************************************************************
ok: [localhost] => {
"msg": "Example Text\n"
}
TASK [cat file] ***************************************************************************************************************************
changed: [localhost]
TASK [echo file body] *********************************************************************************************************************
ok: [localhost] => {
"msg": "Example Text"
}
PLAY RECAP ********************************************************************************************************************************
localhost : ok=6 changed=1 unreachable=0 failed=0
- hosts:
- example
tasks:
- name: copy
copy:
src: example.txt
dest: ./
- name: slurp file
slurp:
path: example.txt
register: slurp_file
- name: echo file body
debug:
msg: "{{ slurp_file.content | b64decode }}"
- name: cat file
shell: cat example.txt
register: cat_file
- name: echo file body
debug:
msg: "{{ cat_file.stdout }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment