ansible_network_ os not valid attribute error

Viewed 349

I am new to Ansible and I am trying to run this playbook. I get an error stating "ansible_network_os is not valid attribute to play". Can you please let me know what could be wrong with my script?

---
- name: configure interfaces setting
  hosts: switches
  connection: network_cli
  ansible_network_os: cisco.ios.ios
  tasks:
    - name: configure interface
      ios_config:
        before:
          - default interface Gi0/3
        lines:
          - ip address 10.10.10.1 255.255.255.0
        after:
          -no shutdown
        parents: interface Gi0/3
2 Answers

ansible_network_os is a variable. It's not a playbook keyword. See for example Prerequisites. To fix the play put the variable among variables. For example,

---
- name: configure interfaces setting
  hosts: switches
  connection: network_cli
  vars:
    ansible_network_os: cisco.ios.ios
  tasks:
    - name: configure interface
      ...

Notes:

  • See Playbook Keywords what keywords can be used at various blocks.

  • The variable ansible_connection can be used also as the play keyword connection. This can be confusing because not all ansible_* variables have keyword equivalent.

  • To avoid this kind of confusion put such variables into the inventory. This is a better place compared to a playbook because the connection type doesn't change in most cases during a play. If it does you can override it anytime on a higher precedence level inside a play. See Understanding variable precedence.

Much appreciated your help, the other issue is resolved by providing the username and password parameter into the play.

Related