gpt4 book ai didi

ansible - 如何有条件地使用状态?

转载 作者:行者123 更新时间:2023-12-05 09:18:03 25 4
gpt4 key购买 nike

我在剧本中有一个blockinfile,它应该存在于不依赖于先前设置的变量的值。暴力解决方案是

  - name: shorewall rules
blockinfile:
dest: /etc/shorewall/rules
state: present
block: |
# settings for machine {{ machine }}
# outgoing internet
ACCEPT {{ machine }} int
# more here
when: active == "y"

- name: shorewall rules
blockinfile:
dest: /etc/shorewall/rules
state: absent
block: |
# settings for machine {{ machine }}
# outgoing internet
ACCEPT {{ machine }} int
# more here
when: active == "n"

有没有办法在 state 中设置条件?

state: present if active == "y" else absent

最佳答案

你可以这样做:

state: "{{ 'present' if active == 'y' else 'absent' }}"

关于ansible - 如何有条件地使用状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45652755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com