合并两个功能相同但时间条件不同的剧本

问题描述

我有2本剧本,从功能上来说,它们的工作原理完全相同,但唯一的区别在于它们的When条件。

我几乎尝试了所有可能的方法,但无法获得同时满足这两个要求的解决方案。

注意:请仅关注“ 何时条件

重要条件其中一个或两个条件为true。 a_include_user或a_exclude_user --extra-vars'{“ a_exclude_user”:[“ auto”]}'

Playbook 1-

- name: skipping Vars
  debug:
    msg: "skipping for {{ keytab.user.name }}"
  when:
    - (keytab.user.name not in a_include_user)

- block:
    - name: removing selected principal
      shell: |
       #!/bin/bash
       ipa-rmkeytab --principal {{ keytab.user.name }}@{{ realm }} --keytab {{ keypath }}loopkey.keytab
      args:
           chdir: "{{ keypath }}"

    - name: replacing  selected pricipal
      expect:
        command: ktutil
        responses:
           ktutil:
              - "addent -password -p {{ keytab.user.name }}@{{ realm }} -k 1 -e {{ sec }}"
              - " wkt {{ keypath}}loopkey.keytab"
              - "quit"
           Password(.*): "{{ keytab.user.pass }}"

  when:
    - (keytab.user.name in a_include_user)

================================================ =======

PLAYBOOK-2


- name: skipping user names
  debug:
    msg: "skipping for {{ keytab.user.name }}"
  when:
    - (keytab.user.name in a_exclude_user)

- block:
    - name: removing selected principal
      shell: |
       #!/bin/bash
       ipa-rmkeytab --principal {{ keytab.user.name }}@{{ realm }} --keytab {{ keypath }}loopkey.keytab
      args:
           chdir: "{{ keypath }}"

    - name: replacing  selected pricipal
      expect:
        command: ktutil
        responses:
           ktutil:
              - "addent -password -p {{ keytab.user.name }}@{{ realm }} -k 1 -e {{ sec }}"
              - " wkt {{ keypath}}loopkey.keytab"
              - "quit"
           Password(.*): "{{ keytab.user.pass }}"

  when:
    - (keytab.user.name not in a_exclude_user)


我怎么能拥有一本足以满足这两个剧本的书本?

我尝试了以下条件- 第一次:

 when:
    - ((keytab.user.name in a_include_user|d('')) and (keytab.user.name not in a_exclude_user)) or ((keytab.user.name in a_include_user) and (keytab.user.name not in a_exclude_user|d('')))

第二次出现

  when:
    - ((keytab.user.name in a_exclude_user) and (keytab.user.name not in a_include_user|d(''))) or ((keytab.user.name in a_exclude_user|d('')) and (keytab.user.name not in a_include_user))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)