arya nair
arya nair

Reputation: 1

ansible ERROR! conflicting action statements: hosts, command while running

- 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

this is my playbook

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

I am encountering this error.
Please help me fix the issue.

Upvotes: 0

Views: 3294

Answers (1)

Jack
Jack

Reputation: 6168

Indents. You need to start a new play with a new set of hosts and a new task list.

- 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

Upvotes: 1

Related Questions