gpt4 book ai didi

salt-stack - 用 salt 状态的符号链接(symbolic link)替换文件

转载 作者:行者123 更新时间:2023-12-04 13:32:25 26 4
gpt4 key购买 nike

我是 SaltStack 的新手。

我正在尝试确保存在符号链接(symbolic link)。

/etc/localtime:
file.symlink:
- target: /usr/share/zoneinfo/Europe/Paris
- file.exists:
- name: /usr/share/zoneinfo/Europe/Paris

当不存在 /etc/localtime 时,结果异常(exception)。 , 或当 /etc/localtime已经是一个符号链接(symbolic link)。但它在 /etc/localtime 时失败是一个常规文件:
----------
State: - file
Name: /etc/localtime
Function: symlink
Result: False
Comment: File exists where the symlink /etc/localtime should be
Changes:

我不知道如何对状态进行编码,以便在创建链接之前删除文件。有什么线索吗?

干杯,
皮埃尔

最佳答案

使用force=True

/etc/locatime:
file.symlink:
- target: /usr/share/zoneinfo/Europe/Paris
- force: True
# Note: file.exists is not valid here and can be removed
# file.exists:
# - name: /usr/share/zoneinfo/Europe/Paris

来自 the documentation :

If the target of the symlink exists and is not a symlink and force is set to False, the state will fail. If force is set to True, the file or directory in the way of the symlink file will be deleted to make room for the symlink, unless backupname is set, when it will be renamed

关于salt-stack - 用 salt 状态的符号链接(symbolic link)替换文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20749361/

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