Language: English
Auth: token‑only (generated by nce_auth)
TLS: self‑signed allowed (validate_certs: false)
Default Base URI: https://weu.naas.huawei.com:18002
- Modules
nce_auth— obtain / revoke token (POST/DELETE/controller/v2/tokens)nce_site— CRUD for Sites (single object, idempotent)nce_device— CRUD for Devices (single object, idempotent)
- Plugins
- Lookup:
nce_lookup—lookup('sites'|'devices', '<identifier|name>') - Inventory:
nce_inventory— builds inventory from devices; strict filename:nce.yml|nce.yaml
- Lookup:
- Conventions enforced
- Inputs under
object(MUST includename) - Uniqueness under
selector(key→value withoutname) - Idempotent modules (detect create vs update automatically)
- Inputs under
- Ansible 2.14+ (recommended 2.15+)
- Python 3.9+
- Access to Huawei iMaster NCE‑Campus tenant view
- Unzip in your project so the path looks like:
<project>/collections/ansible_collections/cd60/nce/ - Export the collections path when running Ansible:
export ANSIBLE_COLLECTIONS_PATHS="$(pwd)"
Requires
ansible-galaxylocally.
# From your project root that contains ./collections/ansible_collections/cd60/nce
ansible-galaxy collection build collections/ansible_collections/cd60/nce -f
# Produces cd60-nce-<version>.tar.gz
ansible-galaxy collection install cd60-nce-*.tar.gz --force---
- name: Get NCE token
hosts: localhost
gather_facts: false
tasks:
- name: Obtain a token
cd60.nce.nce_auth:
base_uri: https://weu.naas.huawei.com:18002
username: "{{ lookup('env', 'NCE_USERNAME') }}"
password: "{{ lookup('env', 'NCE_PASSWORD') }}"
validate_certs: false
register: nce_auth
- debug:
var: nce_auth.token---
- name: Ensure site present
hosts: localhost
gather_facts: false
vars:
nce_token: "{{ lookup('env', 'NCE_TOKEN') | default(none) }}"
tasks:
- name: Create or update site
cd60.nce.nce_site:
token: "{{ nce_token }}"
base_uri: https://weu.naas.huawei.com:18002
validate_certs: false
selector:
organizationName: "Nanjing Research Center"
address: "66 JiangYun Road"
object:
name: "site1"
type: ["AP"]
description: "site1"
latitude: "50"
longitude: "111"
state: present---
- name: Ensure device present
hosts: localhost
gather_facts: false
vars:
nce_token: "{{ lookup('env', 'NCE_TOKEN') }}"
tasks:
- name: Create or update device
cd60.nce.nce_device:
token: "{{ nce_token }}"
base_uri: https://weu.naas.huawei.com:18002
validate_certs: false
selector:
esn: "210235AABBCC"
object:
name: "SW-Edge-01"
esn: "210235AABBCC"
ip: "10.10.10.10"
siteId: "ea25fdbf-8dee-4823-bac2-5bfe8e3359ca"
state: presentRécupérer un site par nom
- name: Lookup a site by name
hosts: localhost
gather_facts: false
vars:
nce_token: "{{ lookup('env', 'NCE_TOKEN') }}"
tasks:
- name: Fetch site object
set_fact:
site_obj: "{{ lookup('cd60.nce.nce_lookup', 'sites', 'site1', base_uri='https://weu.naas.huawei.com:18002', token=nce_token, validate_certs=False) | first }}"
- debug:
var: site_objRécupérer un device par id
- name: Lookup a device by UUID
hosts: localhost
gather_facts: false
vars:
nce_token: "{{ lookup('env', 'NCE_TOKEN') }}"
tasks:
- set_fact:
dev_obj: "{{ lookup('cd60.nce.nce_lookup', 'devices', 'd3f9b5c2-xxxx-xxxx-xxxx-aaaaaaaaaaaa', base_uri='https://weu.naas.huawei.com:18002', token=nce_token, validate_certs=False) | first }}"
- debug:
var: dev_objplugin: cd60.nce.nce_inventory
base_uri: https://weu.naas.huawei.com:18002
token: "{{ nce_token }}"
validate_certs: false
# Optional: filter on sites
# site_ids:
# - "ea25fdbf-8dee-4823-bac2-5bfe8e3359ca"# Lister l’inventaire
ansible-inventory -i nce.yml --list
# Exécuter un module (ex: debug) sur tous les hôtes découverts
ANSIBLE_HOST_KEY_CHECKING=False ansible -i nce.yml all -m debug -a 'var=nce_device.name'Le plugin ajoute chaque device comme hôte avec
ansible_host= nom du device et publie l’objet brut complet sousnce_device.
This target validates create/update/rename/idempotency/delete for the site module.
Provide the following environment variables before running ansible-test integration:
NCE_BASE_URI(e.g.https://weu.naas.huawei.com:18002)NCE_USERNAMEandNCE_PASSWORD(tenant credentials)- Optional:
NCE_VALIDATE_CERTS(true/false) - Optional overrides for test data:
NCE_TEST_SITE_OLD,NCE_TEST_SITE_NEW,NCE_TEST_SITE_CITY,NCE_TEST_SITE_TZ,NCE_TEST_SITE_ADDR,NCE_TEST_SITE_COUNTRY
From the collection root (where galaxy.yml lives), run:
ansible-test integration cd60_nce_site -vv --color --python 3.11You can also run all integration tests:
ansible-test integration --retry-on-error --color -vvThese tests use the collection's FQCN (cd60.nce.cd60_nce_site) and the auth/lookup plugins.
make lint # ansible-lint (tolérant sur quelques règles)
make build # construit l’artifact Galaxy .tar.gzobject: toutes les propriétés configurables d’un objet (MUST includename).selector: mapping clé→valeur pour l’unicité (ne pas inclurename).- Idempotence: pas de paramètre d’opération (création vs mise à jour auto‑détectées).
Propose des issues/feedbacks dans votre dépôt GitOps interne, ou ouvrez un ticket au pôle Réseau & Automatisation.
To create a single-file text bundle (with the extractor script embedded):
make bundle