作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我创建两个 ansible playbook:delete.yml 和 install.yml。可能有类似的问题:我添加到安装someting,但不更改删除
例子:
安装.yml:
---
- name: Add x2go repository
apt_repository: repo='deb http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=present
apt_repository: repo='deb-src http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=present
when: ansible_os_family == "Debian"
tags:
- remote-access-x2go
- name: Install x2go application
apt: name=x2goserver update_cache=yes state=present
apt: name=x2goserver-xsession update_cache=no state=present
when: ansible_os_family == "Debian"
tags:
- remote-access-x2go
删除.yml:
---
- name: Add x2go repository
apt_repository: repo='deb http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=absent
apt_repository: repo='deb-src http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=present
when: ansible_os_family == "Debian"
tags:
- remote-access-x2go
- name: Install x2go application
apt: name=x2goserver update_cache=yes state=absent
apt: name=x2goserver-xsession update_cache=no state=absent
when: ansible_os_family == "Debian"
tags:
- remote-access-x2go
最佳答案
这是一个非常有趣的想法。我个人从未尝试过“撤消”工作流程,但我可以看到这个想法的好处,并且想在某个时候使用它。这是我会做的。
在我的 ansible-role/defaults/main.yml
中,我将定义一个变量标志
# defaults file for ansible-role
flag_undo: false
在我的 ansible-role/tasks/main.yml
中
- name: task foo bar
command: falana dhimaka
- name: undoing task foo bar
command: undo falana dhimaka
when: flag_undo=true
所以默认情况下,我们的标志始终为 false。因此,在安装东西时,我会使用下面的第一个命令来运行我的游戏。要卸载,我会使用第二个命令。
ansible-playbook foo-play.yml
ansible-playbook foo-play.yml --extra-vars "flag_undo=true"
关于ansible - 如何在同一个 ansible 剧本中最好地组织安装和删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28945082/
我是一名优秀的程序员,十分优秀!