Ansible內(nèi)置模塊之get_url
發(fā)布作者:微思網(wǎng)絡(luò) 發(fā)布時(shí)間:2024-10-15 瀏覽量:0次
2. 用 例 # 下載文件到目標(biāo)路徑 選項(xiàng) 必須 類(lèi)型 默認(rèn)值 說(shuō)明 url 是 str 無(wú) 要下載文件的 URL dest 是 str 無(wú) 目標(biāo)文件路徑 mode 否 str 無(wú) 目標(biāo)文件的權(quán)限,如 0644、0755 等 owner 否 str 無(wú) 目標(biāo)文件的所有者 group 否 str 無(wú) 目標(biāo)文件的屬組 checksum 否 str no 用于驗(yàn)證下載文件的 SHA256 校驗(yàn)和 force 否 bool 無(wú) 如果目標(biāo)文件存在,是否強(qiáng)制覆蓋 timeout 否 int no 設(shè)置下載的超時(shí)時(shí)間(秒) headers 否 list 無(wú) 用于下載請(qǐng)求的 HTTP 頭 url_password 否 str 無(wú) 用于下載請(qǐng)求的密碼 url_username 否 str 無(wú) 用于下載請(qǐng)求的用戶(hù)名 validate_certs 否 bool yes 如果為 no,忽略 SSL 證書(shū)驗(yàn)證錯(cuò)誤 use_proxy 否 bool yes 是否使用系統(tǒng)中定義的代理 client_cert 否 str 無(wú) 用于下載請(qǐng)求的客戶(hù)端證書(shū)文件路徑 client_key 否 str 無(wú) 用于下載請(qǐng)求的客戶(hù)端密鑰文件路徑 http_agent 否 str ansible-httpget 設(shè)置下載請(qǐng)求的 HTTP User-Agent 頭
- name: Download a file
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
# 設(shè)置文件權(quán)限和所有者
- name: Download a file and set permissions and owner
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
mode: '0644'
owner: myuser
group: mygroup
# 使用自定義HTTP 頭
- name: Download a file with custom HTTP headers
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
headers:
- 'Authorization: Basic {{ auth_token }}'
# 使用客戶(hù)端證書(shū)和密鑰
- name: Download a file with client certificate and key
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
client_cert: /path/to/client_cert.pem
client_key: /path/to/client_key.pem
# 下載文件并強(qiáng)制覆蓋現(xiàn)有文件
- name: Download a file and force overwrite if it exists
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
force: yes
# 在下載文件時(shí)忽略SSL 證書(shū)錯(cuò)誤
- name: Download a file and ignore SSL certificate errors
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
validate_certs: no
# 下載帶有自定義HTTP 頭的文件
- name: Download file with custom HTTP headers
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
headers:
key1: one
key2: two
# 下載并用checksum (sha256)驗(yàn)證文件完整性
- name: Download file with check (sha256)
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
checksum: sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
# 下載并用checksum (md5)驗(yàn)證文件
- name: Download file with check (md5)
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
checksum: md5:66dffb5228a211e61d6d7ef4a86f5758
# 下載并驗(yàn)證文件的校驗(yàn)和(變量提供校驗(yàn)和)
- name: Download a file and verify checksum
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
checksum: 'sha256:{{ expected_checksum }}'
# 下載并用帶有checksum (md5) 遠(yuǎn)程文件來(lái)驗(yàn)證文件
- name: Download file with checksum url (sha256)
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
checksum: sha256:http://example.com/path/sha256sum.txt
# 獲取需要身份驗(yàn)證的文件
- name: Fetch file that requires authentication.
# username/password only available since 2.8, in older versions you need to use url_username/url_password
ansible.builtin.get_url:
url: http://example.com/path/file.conf
dest: /etc/foo.conf
username: bar
password: '{{ mysecret }}'