首页 > 解决方案 > 错误!冲突的操作语句:主机、运行时的命令

问题描述

- name: test
  hosts: all
  gather_facts: no
  tasks:
    #command 1
  - name: ansible-test command 1
    iosxr_command:
     commands:
     - show inventory
    when: ansible_network_os == 'iosxr'
    register: output
  - debug:
     var: output.stdout

  - name: print command executed
    hosts: 127.0.0.1
    connection: local
    command: 
    - echo sh inventory
    register: output1

  - debug:
     var: output1.stdout

这是我的剧本

ERROR! conflicting action statements: hosts, command

The error appears to be in '/root/container/playbook2.yaml': line 16, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


  - name: print command executed
    ^ here

我遇到了这个错误。
请帮我解决问题。

标签: ansible

解决方案


缩进。您需要使用一组新主机和新任务列表开始新游戏。

- name: test
  hosts: all
  gather_facts: no
  tasks:
    #command 1
  - name: ansible-test command 1
    iosxr_command:
     commands:
     - show inventory
    when: ansible_network_os == 'iosxr'
    register: output
  - debug:
     var: output.stdout

- name: print command executed
  hosts: 127.0.0.1
  connection: local
  gather_facts: no
  tasks:
  - command: echo sh inventory
    register: output1

  - debug:
     var: output1.stdout

推荐阅读