Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以将Ansible Assert函数与YAML文件中的项(而不是列表)进行比较?_Ansible_Jinja2 - Fatal编程技术网

有没有一种方法可以将Ansible Assert函数与YAML文件中的项(而不是列表)进行比较?

有没有一种方法可以将Ansible Assert函数与YAML文件中的项(而不是列表)进行比较?,ansible,jinja2,Ansible,Jinja2,我需要在我的网络设备上应用丢失的日志服务器配置,还需要使用Assert函数将正在运行的配置与ip的in group_vars yaml文件进行比较 我当前的断言函数如下所示: --- - name: Add Logging Server Configuration hosts: nxos tasks: - name: Pre-Change nxos_command: commands: show running-config | include

我需要在我的网络设备上应用丢失的日志服务器配置,还需要使用Assert函数将正在运行的配置与ip的in group_vars yaml文件进行比较

我当前的断言函数如下所示:

---

- name: Add Logging Server Configuration
  hosts: nxos

  tasks:

    - name: Pre-Change
      nxos_command:
         commands: show running-config | include "logging server"
      register: pre_output

    - name: Display Pre-Check
      debug:
        var: pre_output.stdout_lines

    - name: Pre-Configuration Verification Status
      assert:
        that:
          - "'10.1.1.2' not in pre_output.stdout[0] or '10.1.1.3' not in pre_output.stdout[0]"
        fail_msg: "Logging server configuration already exists on the device"
        success_msg: "Logging server configuration is missing, proceeding with adding config on the device"
组变量/all.yml文件:

logging_servers: ["10.1.1.2", "10.1.1.3"]
有没有办法直接与
all.yml
中的项目进行比较,而不是硬编码ip的in-assert函数?

试试这个

-断言:
那就是:记录你的服务器|
选择('in',pre_output.stdout_line.0)|列表|
长度==服务器数量| int
失败消息:“缺少日志服务器配置”
成功消息:“日志服务器配置已存在”
变量:
没有_服务器:{{logging_服务器| length}}”

不清楚您要测试什么输出。它是标准的吗?然后,从
pre\u output.stdout[0]
中删除索引。还是第一行
标准行[0]