首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ansible攻略:变量

Ansible攻略:变量
EN

Stack Overflow用户
提问于 2020-06-24 00:10:15
回答 1查看 145关注 0票数 1

当我按如下方式运行这个剧本时,我的剧本出现了问题

可能-攻略-i inventory junos_config_new.yml -check-vvv

代码语言:javascript
复制
      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列,但也可能位于文件中的其他位置,具体取决于确切的语法问题。

代码语言:javascript
复制
The offending line appears to be:

    register: junos_output1
  - debug:
    ^ here

请告诉我我能做些什么..

EN

回答 1

Stack Overflow用户

发布于 2020-06-24 01:35:37

错误的主要原因似乎是您正在为junos_config模块使用diff。根据文档,该模块不支持diffhttps://docs.ansible.com/ansible/latest/modules/junos_config_module.html

因此,您需要从junos_config任务中删除该diff: true

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

代码语言:javascript
复制
- 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

确保为所有任务正确缩进任务名称和其他任务参数:

代码语言:javascript
复制
- 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格式)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62539120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档