【问题标题】:How can I run certain types of Ansible tasks (without tags)如何运行某些类型的 Ansible 任务(无标签)
【发布时间】:2020-03-11 08:27:53
【问题描述】:

我想在所有主机上定期运行我的copytemplate 任务(以及其他一些任务),以确保配置文件是最新的。 我知道tags,但是如果有人忘记了copy 任务上的标签怎么办?

更好的是,我可以在检查配置文件时排除某些我不感兴趣的任务类型,例如apt吗?

编辑:添加简化示例以希望使我的问题更清楚。

我想跳过下面的apt 任务,只运行copytemplate 任务:

- name: install postfix                                                                                                                                                                                                                                                                                                                      
  apt: name=postfix update_cache=yes state=present

- name: postfix main.cf
  copy:
    src: roles/postfix/files/main.cf
    dest: /etc/opt/ooce/postfix/main.cf

- name: postfix aliases
  template:
    src: roles/postfix/files/aliases
    dest: /etc/aliases

【问题讨论】:

  • 您可以将任务拆分为多个剧本或角色。

标签: ansible


【解决方案1】:

您的信息水平很高。但是,如果您正在寻找跳过某些任务,那么您可以检查“何时”条件来过滤要运行或跳过的某些任务。以下是来自Ansible documentation 的示例。

当: - ansible_facts['distribution'] == "CentOS" - ansible_facts['distribution_major_version'] == "6"

【讨论】:

    猜你喜欢
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    相关资源
    最近更新 更多