【问题标题】:Ansible: Write multiple lines to a file using local_action or another methodAnsible:使用 local_action 或其他方法将多行写入文件
【发布时间】:2016-06-23 07:26:00
【问题描述】:

我正在使用命令:

  • local_action: copy content="安装失败" dest=~/ansible/ansible_log.txt

但是,当我再次这样做时:

  • local_action: copy content="联系我寻求帮助" dest=~/ansible/ansible_log.txt

它用新文本覆盖旧文本。我想要做的是追加到文件而不是替换以前的文本。

我尝试在原始字符串的末尾添加 /n 无济于事。

【问题讨论】:

    标签: ansible ansible-playbook


    【解决方案1】:

    lineinfile 模块呢:

    local_action:
        module: lineinfile
        dest: "~/ansible/ansible_log.txt"
        line: "The installation failed"
        create: yes
    local_action:
        module: lineinfile
        dest: "~/ansible/ansible_log.txt"
        line: "Contact me for assistance"
    

    【讨论】:

    • 或模板。风险低得多。
    猜你喜欢
    • 2011-12-23
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    相关资源
    最近更新 更多