I am currently trying the Ansible collection found here: https://github.com/laidbackware/ansible-for-nsxt, but I keep getting a permissions error with the code below. This is a fork from the ansible-for-NSX-T
collection though it should work since it calls the policy mode API for services at policy/apiv1/infra/services/
.
It seems like a permissions problem though, when I call the API directly via cURL, it works fine.
---
- name: Create NSX-T Service
hosts: localhost
gather_facts: no
tasks:
- name: Create a new service
nsxt_policy_service:
hostname: "{{ nsx_manager_hostname }}"
username: "{{ nsx_manager_username }}"
password: "{{ nsx_manager_password }}"
display_name: "My New Service"
description: "Example service for testing"
service_type: "L4LB" # Specify the appropriate service type (e.g., L4LB, L7LB, etc.)
ports:
- protocol: "TCP"
port: 80
- protocol: "TCP"
port: 443
state: present
register: created_service
- name: Display the created service details
debug:
var: created_service
The error I get is this one:
TASK [Define new service in NSX-T] *********************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"cache_control": "no-cache, no-store, max-age=0, must-revalidate", "changed": false, "connection": "close", "content_length": "141", "content_type": "application/json;charset=UTF-8", "date": "Wed, 12 Jun 2024 23:35:52 GMT", "elapsed": 0, "expires": "0", "json": {"error_code": 403, "error_message": "The credentials were incorrect or the account specified has been locked.", "module_name": "common-services"}, "msg": "Status code was 403 and not [200]: HTTP Error 403: ", "pragma": "no-cache", "redirected": false, "server": "NSX", "status": 403, "strict_transport_security": "max-age=31536000 ; includeSubDomains", "url": "
https://x-x.x.x.com/policy/api/v1/infra/services/HTTP-ID"
, "x_content_type_options": "nosniff", "x_frame_options": "SAMEORIGIN", "x_xss_protection": "1; mode=block"}