huaweidatacom / huaweidatacom.ac / 1.0.0 / module / ac_tenant Manages Tenant on HUAWEI iMaster NCE-Fabric Controller. Authors: ZhiwenZhang (@maomao1995)huaweidatacom.ac.ac_tenant (1.0.0) — module
Install with ansible-galaxy collection install huaweidatacom.ac:==1.0.0
collections: - name: huaweidatacom.ac version: 1.0.0
Manages Tenant on HUAWEI iMaster NCE-Fabric Controller(AC).
- name: Create Tenant hosts: localhost serial: True vars: now_time: "{{ansible_date_time.date}} {{ansible_date_time.time}}" token_id: "{{lookup('file','/tmp/ansible-temp')}}" vars_prompt: - name: "tenant_name" prompt: "Please input tenant name " private: no - name: "tenant_desc" prompt: "Please input tenant description " private: no - name: "fabric_id" prompt: "Please input fabric id " private: no tasks: - name: check tenant_name is null fail: msg: "Create Tenant fail! tenant_name is null" when: tenant_name == '' - name: fabric_id is not null when: fabric_id != '' vars: fabricIds: ["{{fabric_id}}"] debug: var=fabricIds - name: fabric_id is null when: fabric_id == '' vars: fabricIds: [] debug: var=fabricIds - name: Create tenant "{{tenant_name}}" tags: create_tenant vars: tenant_info: id: "{{ansible_date_time.iso8601_micro | to_uuid}}" name: "{{tenant_name}}" description: "{{tenant_desc}}" producer: "default" createAt: "{{now_time}}" updateAt: "{{now_time}}" resPool: fabricIds: "{{fabric_id}}" tenant_infos: tenant: ["{{tenant_info}}"] uri: url: 'https://{{north_ip}}:{{north_port}}/controller/dc/v3/tenants' method: POST body: '{{tenant_infos}}' body_format: json validate_certs: False return_content: yes headers: X-ACCESS-TOKEN: "{{token_id}}" Accept: application/json Content_Type: application/json status_code: 204 register: tenant_result - name: response from create tenant debug: msg: "{{tenant_result}}"
- name: Update Tenant hosts: localhost serial: True vars: now_time: "{{ansible_date_time.date}} {{ansible_date_time.time}}" token_id: "{{lookup('file','/tmp/ansible-temp')}}" vars_prompt: - name: "tenant_id" prompt: "Please input the tenant id that you want to update " private: no - name: "tenant_name" prompt: "Please input tenant name " private: no - name: "tenant_desc" prompt: "Please input tenant description " private: no tasks: - name: check tenant_id is null fail: msg: "Update Tenant fail! tenant_id is null" when: tenant_id == '' - name: check tenant_name is null fail: msg: "Update Tenant fail! tenant_name is null" when: tenant_name == '' - name: Update tenant "{{tenant_id}}" tags: update_tenant vars: tenant_info: id: "{{tenant_id}}" name: "{{tenant_name}}" description: "{{tenant_desc}}" updateAt: "{{now_time}}" tenant_infos: tenant: ["{{tenant_info}}"] uri: url: 'https://{{north_ip}}:{{north_port}}/controller/dc/v3/tenants/tenant/{{tenant_id}}' method: PUT body: '{{tenant_infos}}' body_format: json validate_certs: False return_content: yes headers: X-ACCESS-TOKEN: "{{token_id}}" Accept: application/json Content_Type: application/json status_code: 200 register: tenant_result ignore_errors: yes - name: response from update a tenant debug: msg: "{{tenant_result}}"
- name: Query Tenant hosts: localhost serial: True vars: token_id: "{{lookup('file','/tmp/ansible-temp')}}" vars_prompt: - name: "tenant_id" prompt: "Please input the tenant id that you want to query " private: no tasks: - name: qeury tenants tags: qeury_tenants when: tenant_id == '' uri: url: 'https://{{north_ip}}:{{north_port}}/controller/dc/v3/tenants' method: GET validate_certs: False return_content: yes headers: X-ACCESS-TOKEN: "{{token_id}}" Accept: application/json Content_Type: application/json status_code: 200 register: tenants_result ignore_errors: yes - name: qeury tenant "{{tenant_id}}" tags: qeury_tenant when: tenant_id != '' uri: url: 'https://{{north_ip}}:{{north_port}}/controller/dc/v3/tenants/tenant/{{tenant_id}}' method: GET validate_certs: False return_content: yes headers: X-ACCESS-TOKEN: "{{token_id}}" Accept: application/json Content_Type: application/json status_code: 200 register: tenant_result ignore_errors: yes - name: response from get tenants when: tenant_id == '' debug: msg: "{{tenants_result.json.tenant}}" - name: response from query a tenant when: tenant_id != '' debug: msg: "{{tenant_result.json.tenant}}"
- name: Delete Tenant hosts: localhost serial: True vars: token_id: "{{lookup('file','/tmp/ansible-temp')}}" vars_prompt: - name: "tenant_id" prompt: "Please input the tenant id that you want to delete " private: no tasks: - name: check tenant_id is null fail: msg: "Delete Tenant fail! tenant_id is null" when: tenant_id == '' - name: Delete tenant "{{tenant_id}}" tags: delete_tenant uri: url: 'https://{{north_ip}}:{{north_port}}/controller/dc/v3/tenants/tenant/{{tenant_id}}' method: DELETE validate_certs: False return_content: yes headers: X-ACCESS-TOKEN: "{{token_id}}" Accept: application/json Content_Type: application/json status_code: 204 register: tenant_result ignore_errors: yes - name: response from delete a tenant debug: msg: "{{tenant_result}}"
fabric_id: description: - AC Fabric id. tenant_id: description: - AC Tenant id. tenant_desc: description: - AC Tenant description. tenant_name: description: - AC Tenant name.