use*_*691 1 ansible ansible-2.x
我具有下载脚本文件的角色,如何在执行之前使用md5sum检查文件的真实性?
- name: Add xx official repository for ubuntu/debain
get_url:
url: https://script.deb.sh
dest: /opt/script.db.sh
- name: Execute the script
script: /opt/script.db.sh
Run Code Online (Sandbox Code Playgroud)
如果您没有使用get_url选项,则在文件放置到位置后,stat使用此处记录的get_checksum选项调用模块。
- name: Get sha256 sum of script
stat:
path: /opt/script.db.sh
checksum_algorithm: sha256
get_checksum: yes
register: shell_stat
- name: Verify sha256sum of script before execution.
fail:
msg: "Failure, file is not correct."
when: shell_stat.stat.checksum != '19d6105fa1a581cf3ad38f67080b6d55cb152b5441ae8bdf194e593f292f31e9'
- name: Execute the script
script: /opt/script.db.sh
Run Code Online (Sandbox Code Playgroud)
更新行中的总和when:以匹配您期望的文件。
生成校验和(在此示例中为sha256)在您的操作系统上有所不同。在大多数Linux发行版sha256sum {filename}上,请使用命令;在OSX上,请使用shasum -a 256 {filename}。
| 归档时间: |
|
| 查看次数: |
2108 次 |
| 最近记录: |