Ansible剧本:变量

Ansible剧本:变量,ansible,Ansible,当我运行此剧本时,我的剧本有问题,如下所示 ansible playbook–i库存junos_config_new.yml–检查–vvv name: Juniper SRX configuration compliance checks hosts: juniper gather_facts: false tasks: set_fact: config_directory: '{{ "/home/myfo

当我运行此剧本时,我的剧本有问题,如下所示

ansible playbook–i库存junos_config_new.yml–检查–vvv

      name: Juniper SRX configuration compliance checks 
      hosts: juniper
      gather_facts: false
      tasks:
      set_fact:
         config_directory: '{{ "/home/myfolder/ansible_junos/files/" }}'
     - name: Syslog server check
        junipernetworks.junos.junos_config:
           src:'{{ config_directory }}/syslog_config.txt'
           src_format: set
           comment: Ensure that appropriate Syslog server configured 
        register: junos_output
        diff: true
      - debug:
          msg: Syslog server check - This check has failed with the following output({{ junos_output.diff.prepared }})
        when: junos_output.changed 
      - debug:
          msg: Syslog server check - This check has failed with the following output({{ junos_output.diff.prepared }})
         when: junos_output.changed
      - name: Admin credentials check
         junipernetworks.junos.junos_config:
            src: '{{ config_directory }}/admin_user.txt'
            comment: Ensure that Admin user have been created
         diff: true
         register: junos_output1
      - debug:
          var: junos_output1  ***************************************failed section 
      - debug:
          msg: Admin credentials check - This check has passed with the following output({{ junos_output1.diff.prepared }})
        when: not junos_output1.changed 
      - debug:
          msg: Admin credentials check - This check has failed with the following output({{ junos_output1.diff.prepared }})
        when: junos_output1.changed 
      - name: NTP Server check 
          junipernetworks.junos.junos_config:
             src: '{{ config_directory }}/NTP_server.txt'
             comment: Ensure that correct NTP servers has been configured
          diff: true
      - debug:
          var: junos_output2
      - debug:
          msg: NTP Server check  - This check has passed with the following output({{ junos_output2.diff.prepared }})
         when: not junos_output.changed 
      - debug:
          msg: NTP Server check  - This check has failed with the following output({{ junos_output2.diff.prepared }})
        when: junos_output.changed 
 
      - name: Idle timeout check 
          junipernetworks.junos.junos_config:
             src: '{{ config_directory }}/idle_timeout.txt'
             comment: Ensure that idle timeout has been configured
          diff: true
      - debug:
          var: junos_output3
       - debug:
           msg: Idle timeout check   - This check has passed with the following output({{ junos_output3.diff.prepared }})
          when: not junos_output.changed 
       - debug:
           msg: Idle timeout check   - This check has failed with the following output({{ junos_output3.diff.prepared }})
          when: junos_output.changed 
错误出现在“/home/gefelas/ansible_junos/junos_config_new.yml”中:第30行第5列,但可能是 根据确切的语法问题,在文件中的其他位置

The offending line appears to be:

    register: junos_output1
  - debug:
    ^ here

请告诉我可以更改的内容。

错误的主要原因似乎是您正在使用
diff
作为
junos\u config
模块。根据文档,此模块不支持
diff

因此,您需要从
junos\u config
任务中删除
diff:true

另一方面,您似乎也有多个缩进问题,例如,这不是正确的缩进:

- name: Admin credentials check
   junipernetworks.junos.junos_config:
      src: '{{ config_directory }}/admin_user.txt'
      comment: Ensure that Admin user have been created
   register: junos_output1
确保为所有任务正确缩进任务名称和其他任务参数,如:

- name: Admin credentials check
  junipernetworks.junos.junos_config:
    src: '{{ config_directory }}/admin_user.txt'
    comment: Ensure that Admin user have been created
  register: junos_output1

因此,我建议检查您的文件并检查所有任务的缩进(请注意,这也可能是由于堆栈溢出格式造成的)。

错误的主要原因似乎是您正在使用
diff
作为
junos\u config
模块。根据文档,此模块不支持
diff

因此,您需要从
junos\u config
任务中删除
diff:true

另一方面,您似乎也有多个缩进问题,例如,这不是正确的缩进:

- name: Admin credentials check
   junipernetworks.junos.junos_config:
      src: '{{ config_directory }}/admin_user.txt'
      comment: Ensure that Admin user have been created
   register: junos_output1
确保为所有任务正确缩进任务名称和其他任务参数,如:

- name: Admin credentials check
  junipernetworks.junos.junos_config:
    src: '{{ config_directory }}/admin_user.txt'
    comment: Ensure that Admin user have been created
  register: junos_output1

因此,我建议检查您的文件并检查所有任务的缩进(注意,这也可能是由于StackOverflow格式).

这是playbook执行的输出这是playbook执行的输出我也这么认为,但是如果你看
diff
是一个有效的属性。他们只是将它与
juniper\u junos\u config:
一起使用,而不是
junipernetworks.junos.junos\u config:
也许这就是问题所在。除了我的评论之外。有模块和模块。第一个没有属性
diff
。第二个有。错误是:'dict object'没有属性'diff'表示此字段不是从模块返回的,因此可能值得调查。我也这么认为,但如果您查看
diff
是一个有效属性。他们只是将它与
juniper\u junos\u config:
一起使用,而不是
junipernetworks.junos.junos\u config:
也许这就是问题所在。除了我的评论之外。有模块和模块。第一个没有属性
diff
。第二个有它。错误是:'dict object'没有属性'diff',表明此字段不是从模块返回的,因此可能值得研究。