HuaweiDatacomm / ansible-gen

a tool to generate ansible API automatically for huawei net-engine ansible plugin
Other
6 stars 3 forks source link

Huawei S5731-S24P4X edit-config issue #18

Open cunzolo opened 2 years ago

cunzolo commented 2 years ago

Hi to all,

I'm trying to use ansible-gen with Huawei S5731-S24P4X. The "get" operation is working but I'm unable to use the "edit-config" command in ansible.

Error message: fatal: [rt1]: FAILED! => {"changed": false, "msg": "b'An unexpected element is present.(Mandatory choice \"edit-content\" missing a case branch.).'"} Files.zip

niubiwocao commented 2 years ago

fatal: [rt1]: FAILED! => {"changed": false, "msg": "b'An unexpected element is present.(Mandatory choice "edit-content" missing a case branch.).'"} First, in your device_name.xml file,under <edit-config> label missing Mandatory Choice
`

` this must be choiced. Second,you can refer to https://github.com/HuaweiDatacomm/ansible-gen-examples/blob/main/vpn-service-example/api_desc/vpn/config/config_interface/config_interface.xml to write your own xml files.

cunzolo commented 2 years ago

Thanks for your fast reply!

Added <target> <running/> </target>. I already checked that file, but with no luck :). What am I missing? I just want to change the device hostname.

niubiwocao commented 2 years ago

hello,please refer to the following XML file of the NE40E router(change the device hostname) to adapt to Huawei S5731-S24P4X switch.

<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="cli2xml-0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <edit-config>
    <target>
      <running/>
    </target>
    <default-operation>none</default-operation>
    <config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
      <system xmlns="urn:huawei:yang:huawei-system">
        <system-info nc:operation="merge">
          <sys-name></sys-name>
          <sys-contact></sys-contact>
          <sys-location></sys-location>
        </system-info>
      </system>
    </config>
  </edit-config>
</rpc>

if it also doesn't working ,please paste your yaml playbook and -vvv debuglog.

cunzolo commented 2 years ago

Hi,

host file:

[routers]
rt1 ansible_host=172.16.13.40

[routers:vars]
ansible_network_os=community.network.ne
ansible_user=argonet
ansible_password=Argo2022!
ansible_connection=netconf
; ansible_port=830

Ansible playbook:

- name: CloudEngine netconf test
  hosts: rt1
  # connection: netconf
  gather_facts: no
  vars:
    cli:
      host: "172.16.13.35"
      port: "830"
      username: "argonet"
      password: "Argo2022!"
      transport: netconf

  tasks:

  - name: get_device_name
    get_device_name:
      operation_type: get
      device-state:
        name:
          get_all: True

    register: print_path

  - name: Show Netconf
    debug:
        msg: "{{ print_path }}"

  - name: config_device_example
    config_device:
      operation_type: config
      operation_specs:
        - path: /config/device
          operation: merge
      device:
        name: "switchTest"

config_device.xml:

<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="cli2xml-0">
  <edit-config>
  <target>
    <running/>
  </target>
  <default-operation>none</default-operation>
    <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <device xmlns="urn:huawei:params:xml:ns:yang:huawei-device">
        <name></name>
      </device>
    </config>
  </edit-config>
</rpc>

config_device_example.xml:

<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="cli2xml-0">
  <edit-config>
  <target>
    <running/>
  </target>
  <default-operation>none</default-operation>
    <config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
      <device xmlns="urn:huawei:params:xml:ns:yang:huawei-device" nc:operation="merge">
        <name>testExample</name>
      </device>
    </config>
  </edit-config>
</rpc>

Example to set device name on V200R021C00: [(https://support.huawei.com/enterprise/en/doc/EDOC1100212422/617e0ff2/setting-a-device-name)]

Thanks!! ansible-execution.txt

niubiwocao commented 2 years ago

Hello,how are you today? if you just want to change the device hostname, you no need to use ansible-gen. you can just refer to https://github.com/ansible-collections/community.network/blob/main/plugins/modules/network/cloudengine/ce_config.py line 156-173 Ansible playbook(huawei-test.yaml) like this:

- name: CloudEngine NetWork_CLI  test
  hosts: rt1
  connection: local
  gather_facts: no
  vars:
    cli:
      host: "172.16.13.35"
      port: "830"
      username: "argonet"
      password: "Argo2022!"
      transport: cli
  tasks:
  - name: "Configure top level configuration and save it"
    community.network.ce_config:
      lines: sysname ciao
      save: yes
      provider: "{{ cli }}"

Host file(hosts.ini) like this:

[all:vars] 
ansible_connection=network_cli
[rt1]
172.16.13.35  ansible_ssh_port=830 ansible_ssh_user=argonet  ansible_ssh_pass=Argo2022!  ansible_network_os=ce
cunzolo commented 2 years ago

Hi niubiwocao,

I'm fine, what about you?

Yes, it would be easier, but we wanted to manage the device configuration through Netconf/Yang :) The work you have done with ansible-gen is outstanding, it would be a shame not to use it..

niubiwocao commented 2 years ago

hello,I'm fine too. You misunderstand me.Of course you can use ansible-gen tool and manage the device configuration through Netconf/Yang. All you have to do is simply change this in host file: ansible_network_os=huaweidatacom.ne.ne

cunzolo commented 2 years ago

Hi niubiwocao, It works now. Thank you very much, it was my mistake... So, "community.network.ne" does not exists, Is It right? The right network os could be "community network.ce" and "huaweidatacom.ne.ne"

niubiwocao commented 2 years ago

Hi niubiwocao, It works now. Thank you very much, it was my mistake... So, "community.network.ne" does not exists, Is It right? The right network os could be "community network.ce" and "huaweidatacom.ne.ne"

Yes, that's right.we create our own ansible_collections huaweidatacom.ne,the community.network.ne does not exists,ansible_network_os=ce can redirect to community.network.ce automatically.