6

我是盐堆的新手。

我正在尝试确保存在符号链接。

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

当不存在时,结果是例外/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:   

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

干杯,皮埃尔

4

1 回答 1

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

文档中

如果符号链接的目标存在并且不是符号链接并且 force 设置为 False,则状态将失败。如果 force 设置为 True,则将删除 symlink 文件路径中的文件或目录,为 symlink 腾出空间,除非设置了 backupname,否则将被重命名

于 2013-12-23T22:21:27.647 回答