TL;DR
ansible.builtin.uri
でコンテンツを取ってきて ansible.builtin.shell
の stdin
を使って流し込む
サンプル
たとえばrustupのインストールは公式ドキュメントでは次のようなスクリプトを使っている
curl -sSf https://sh.rustup.rs | sh -s -- -y
これをこのまま ansible.builtin.shell
に記述して実行すると warning が出ます。たとえばこういう具合にすると
- name: Install rustup ansible.builtin.shell: cmd: curl -sSf https://sh.rustup.rs | sh -s -- -y
実行時にこういうふうにwarningがでます。
TASK [common : Run rustup] ********************************************************************************** [WARNING]: Consider using the get_url or uri module rather than running 'curl'. If you need to use command because get_url or uri is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message. changed: [dev]
指摘のように ansible.builtin.uri
と ansible.builtin.shell
の stdin
を使えばパイプの部分をそのまま表現できるのでそのように書き換えます。
- name: Fetch rustup ansible.builtin.uri: url: https://sh.rustup.rs return_content: yes register: rustup_installer - name: Run rustup installer ansible.builtin.shell: cmd: sh -s -- -y stdin: "{{ rustup_installer.content }}"