5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ansible—リモートマシンのファイルの中身を読む

Last updated at Posted at 2018-08-01

slurp モジュールを使う

  • 結果を register でいちど変数に入れる
    • slurpで取れた文字列は base64 decode する必要があるっぽい。
  • 次に debug モジュールで表示させる
in_some_playbook_tasks.yml
...
    - name: slurp file
      slurp:
        path: example.txt
      register: slurp_file

    - name: echo file body
      debug:
        msg: "{{ slurp_file.content | b64decode }}"

slurp - Slurps a file from remote nodes — Ansible Documentation

shell モジュールを使う

素直にcatしてして標準出力を見る方法

in_some_playbook_tasks.yml
...
    - name: cat file
      shell: cat example.txt
      register: cat_file

    - name: echo file body
      debug:
        msg: "{{ cat_file.stdout }}"

lookup は?

こちらはリモートマシンではなく、手元 ( Control Machine ) のファイルを見る方法のようだ。

file - read file contents — Ansible Documentation

環境

  • ansible 2.6.1

Gist

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?