ansible - 仅在 apt 任务第一次安装软件包时复制文件
问题描述
我想知道如何最好地在 Ansible 中完成这个(希望如此)简单的任务:
在 playbook 中,当第一次安装 dnsmasq apt 包时,将 /etc/dnsmasq.conf 备份到 /etc/dnsmasq.conf.orig,然后再继续执行任何其他任务。
类似于下面的代码?
- name: 'Ensure dnsmasq package is installed'
apt:
name: dnsmasq
state: present
notify: Backup original /etc/dnsmasq.conf file
- name: Backup original /etc/dnsmasq.conf file
copy:
remote_src: yes
src: /etc/dnsmasq.conf
dest: /etc/dnsmasq.conf.orig
when: ONLY IF WE JUST INSTALLED THE PACKAGE ABOVE
解决方案
force: no
复制模块中的选项将仅在文件不存在时复制文件(即您从未安装和复制原始文件)。– Zeitounator 昨天
使用“力”就可以了,而且是最简单的方法,谢谢大家!
(将其创建为答案,因为我无法将评论标记为答案)。
推荐阅读
- javascript - JavaScript 测验问题,继续点击
- tensorflow - keras:model.fit_generator 抛出错误
- python-3.x - discord.ext.commands.errors.MissingPermissions:您缺少运行此命令的静音成员权限
- flutter - 颤动父子复选框
- asp.net - 有没有办法在不更改控制器文件名的情况下更改控制器名称?
- javascript - Material-UI 的 Dialog 如何允许在对话框后面进行交互?
- git - git-multimail 排除 git diff 和后续电子邮件
- matlab - 使用 Matlab 求解使用 Euler 方法的 ODE 系统
- google-cloud-platform - 从 gcp 中的 stackdriver-agent 获取 vm 正常运行时间数据?
- plot - 如何在 Gnuplot 中拟合 f(x)=a*sin^2(b*x^2 + c)