【问题标题】:Need custom backup filenames for file copy using Ansible需要使用 Ansible 进行文件复制的自定义备份文件名
【发布时间】:2019-07-19 02:25:25
【问题描述】:

我已经设置/数组的主机属于以下三类,即

  1. source_hosts(多台服务器)
  2. ansible_host(单服务器)
  3. destination_hosts。 (多台服务器)

根据我们的架构,计划执行以下步骤。

  1. 验证文件是否存在 source_hosts 并具有源用户的复制权限。此外,验证目标中的“文件夹路径”是否存在并且是否具有复制文件的权限。检查我们是否在目的地上没有“空间不足”。

  2. 如果上述验证成功,文件应该从 source_host 复制到 ansible_server 注意:我打算为这个http://docs.ansible.com/ansible/fetch_module.html使用ansible的fetch模块

  3. 应从 ansible 服务器将文件复制到目标服务器的相应位置。 注意:我打算为此使用 ansible 的复制模块 http://docs.ansible.com/ansible/copy_module.html

  4. 如果目标服务器上已经存在该文件,则必须使用标识符“tkt432”以及时间戳创建备份。 注意:同样,我计划使用复制模块进行备份,但我不知道如何将标识符附加到备份文件中。据我所知,该模块没有任何将自定义标识符附加到文件名的功能。

我有以下顾虑。

  1. 解决步骤 1 的理想 ansible 模块是什么?
  2. 如何解决第 4 步中突出显示的问题?
  3. 欢迎提出任何其他建议。

【问题讨论】:

    标签: file ansible copy copy-paste


    【解决方案1】:

    问:“What would be the ideal ansible module to address Step 1 ?

    A:模块 filestat。检查“空间不足”请参阅Using ansible to manage disk space

    问:“How do I address the issue highlighted in Step 4 ? If the file already exists on the destination server a backup must be created with an identifier say "tkt432" along with the timestamp.

    A:引用copy模块的参数

    备份 - 创建包含时间戳的备份文件...

    备份文件的扩展名和位置都不是可选的。见add optional backup_dir for the backup option #16305

    问:“Any other suggestions are welcomed.

    A:看看模块synchronize


    问:“1. Is there any module to check file/folder permissions (rights) for copy-paste operation with that user id?

    答:Ansible 中没有复制粘贴操作。

    问:“Requesting more inputs on how we can append identifiers like "tkt432" to backup filenames while using "copy" modules backup option or any other good solution.

    A:没有更多的输入。 Ansible 不这样做。

    问:“I feel I won't be able to use the copy module and will have to fallback to writing shell scripts for the above-mentioned issues.

    答:是的。模块 shell 和 command 可以帮助解决这个问题。

    【讨论】:

    • 1.是否有任何模块可以使用该用户 ID 检查文件/文件夹权限(权限)以进行复制粘贴操作。 2. 请求更多关于我们如何在使用“复制”模块备份选项或任何其他好的解决方案时将“tkt432”等标识符附加到备份文件名的输入。我觉得我将无法使用复制模块,并且必须回退到为上述问题编写 shell 脚本。
    • 我已经回答了这些问题,但我觉得范围太广了。请参阅 What topics can I ask about here?How do I ask a good question?。如果问题跟在How to create a Minimal, Reproducible Example 后面,那么问题得到回答的机会就更大。
    猜你喜欢
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多