Ansible:get_urlモジュールについて(Ansible 2.9.6)

インフラサーバ

get_url モジュールについて

get_url モジュールを使用することで、Web等からファイルをダウンロードすることができます。

なお、Ansible では command モジュール等で wget コマンドを使用してダウンロードする方法は推奨されていません。wget を使用した場合、エラーにはなりませんが以下のような警告メッセージが表示されます。

[WARNING]: Consider using the get_url or uri module rather than running 'wget'.  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.

主なパラメータ

パラメータ必須選択肢/デフォルト説明
urlダウンロード元の HTTP, HTTPS, または FTP の URL
destダウンロード先ディレクトリの絶対パス
ownerダウンロードしたファイルの所有者
groupダウンロードしたファイルの所有グループ
modeダウンロードしたファイルの権限
例:“0664”、”u=rw,g=r,o=r”

使用例

作業環境

  • CentOS 8.0
  • Python 3.7.7
  • Ansible 2.9.6

使用例

  • 次の URL から bind パッケージを /tmp にダウンロード
    • https://downloads.isc.org/isc/bind9/9.16.2/bind-9.16.2.tar.xz

■ playbook.yml

- hosts: all
  become: yes
  tasks:
    - name: download bind
      get_url:
        url: https://downloads.isc.org/isc/bind9/9.16.2/bind-9.16.2.tar.xz
        dest: /tmp

■ Ansible 実行後の状態

# ls -l /tmp
total 4456
-rw-r--r-- 1 root root 4559216 Apr 16 01:39 bind-9.16.2.tar.xz

―――――――――――――

タイトルとURLをコピーしました