gpt4 book ai didi

ansible - 在ansible中检查文件的真实性

转载 作者:行者123 更新时间:2023-12-04 14:33:11 25 4
gpt4 key购买 nike

我有一个下载脚本文件的 ansible 角色,如何在执行前使用 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
  • 我想在下载文件之前检查真实性 - 这可以在 ansible 中实现吗?
  • 最佳答案

    如果您没有使用 get_url 选项,则在文件位于该位置后,调用 stat使用 get_checksum 的模块选项为 documented here .

    - 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

    更新 when: 上的总和行以匹配您期望的文件。

    生成校验和(在本例中为 sha256)因您的操作系统而异。在大多数 Linux 发行版上使用 sha256sum {filename}命令,在 OSX 上,使用 shasum -a 256 {filename} .

    关于ansible - 在ansible中检查文件的真实性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45287269/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com