用盐状态的符号链接替换文件

Pie*_*rre 6 salt-stack

我是盐堆的新手.

我正在努力确保存在符号链接.

/etc/localtime:
  file.symlink:
    - target: /usr/share/zoneinfo/Europe/Paris
    - file.exists:
      - name: /usr/share/zoneinfo/Europe/Paris
Run Code Online (Sandbox Code Playgroud)

当没有存在/etc/localtime或者/etc/localtime已经是符号链接时,结果是例外.但它/etc/localtime是常规文件时失败:

----------
State: - file
Name:      /etc/localtime
Function:  symlink
    Result:    False
    Comment:   File exists where the symlink /etc/localtime should be
    Changes:   
Run Code Online (Sandbox Code Playgroud)

我无法想象如何编码状态,因此在创建链接之前删除文件.任何线索?

干杯,皮埃尔

Dan*_*ite 13

使用 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
Run Code Online (Sandbox Code Playgroud)

文档:

如果符号链接的目标存在且不是符号链接且force设置为False,则状态将失败.如果force设置为True,则将删除符号链接文件中的文件或目录,以便为符号链接腾出空间,除非设置了backupname,何时重命名