【发布时间】:2021-06-28 13:00:59
【问题描述】:
我只想从 yaml 文件 download.yaml 中下载文件,前提是它们已更改。
我已经找到了这个https://stackoverflow.com/a/22668463/10966928,但似乎 ansible 仍然会下载整个文件,即使它没有更改
来自 playbook.yaml 的任务:
tasks:
- name: Download File
get_url:
url="{{ item.value.url }}"
dest="{{ item.value.dest }}{{item.value.file }}"
loop: "{{ lookup('dict', dl) }}"
下载.yaml:
dl:
4mlinux:
dest: /var/www/html/live/asset-mirror/releases/download/36.1-39ff9a19/
file: vmlinuz
url: https://github.com/netbootxyz/asset-mirror/releases/download/36.1-39ff9a19/vmlinuz
4mlinux-antivirus:
dest: /var/www/html/live/asset-mirror/releases/download/37.0-0.103.2-ba9e3ece/
file: vmlinuz
url: https://github.com/netbootxyz/asset-mirror/releases/download/37.0-0.103.2-ba9e3ece/vmlinuz
4mlinux-bakandimg:
dest: /var/www/html/live/asset-mirror/releases/download/36.0-262576bf/
file: vmlinuz
url: https://github.com/netbootxyz/asset-mirror/releases/download/36.0-262576bf/vmlinuz
编辑:
为了让我的问题更清楚。
Github 不提供发布的哈希值,请参阅此处Where to get MD5 hashes from a GitHub release?
我想避免自己计算校验和,因为download.yaml 是从另一个 yaml 文件生成的。
如果get_url 模块只检查文件的大小就足够了。
编辑2:
Ansible 仍然会下载整个文件。
这是一个详细输出示例:
ok: [127.0.0.1] => (item={'key': 'regolith-current', 'value': {'dest': '/var/www/html/live/ubuntu-squash/releases/download/1.2-0f285b8f/', 'file': 'filesystem.squashfs', 'url': 'https://github.com/netbootxyz/ubuntu-squash/releases/download/1.2-0f285b8f/filesystem.squashfs'}}) => {
"ansible_loop_var": "item",
"changed": false,
"checksum_dest": "f81cc8c2e941746ec359d93ab4ce6b14f75af225",
"checksum_src": "f81cc8c2e941746ec359d93ab4ce6b14f75af225",
"dest": "/var/www/html/live/ubuntu-squash/releases/download/1.2-0f285b8f/filesystem.squashfs",
"elapsed": 94,
"gid": 0,
"group": "root",
"item": {
"key": "regolith-current",
"value": {
"dest": "/var/www/html/live/ubuntu-squash/releases/download/1.2-0f285b8f/",
"file": "filesystem.squashfs",
"url": "https://github.com/netbootxyz/ubuntu-squash/releases/download/1.2-0f285b8f/filesystem.squashfs"
}
},
"md5sum": "285b019b7a2d91c5400b6c9991de2a60",
"mode": "0644",
"msg": "OK (2097151999 bytes)",
"owner": "root",
"size": 2097151999,
"src": "/root/.ansible/tmp/ansible-tmp-1624984184.2966168-188394881121369/tmphilspaat",
"state": "file",
"status_code": 200,
"uid": 0,
"url": "https://github.com/netbootxyz/ubuntu-squash/releases/download/1.2-0f285b8f/filesystem.squashfs"}
如您所见
"src": "/root/.ansible/tmp/ansible-tmp-1624984184.2966168-188394881121369/tmphilspaat"
和"elapsed": 94
【问题讨论】:
标签: ansible