Giter Club home page Giter Club logo

ansible-role-avisdk's Introduction

DEPRECATED

Ansible Galaxy

โ›”๏ธ DEPRECATED: This repo is no longer supported, please consider using https://github.com/vmware/ansible-collection-alb instead since this role is migrated to ansible collections.

Using this role, you will be able to use the latest version, and version specific Avi Ansible Modules.

Requirements

  • python >= 2.6
  • avisdk
  • requests-toolbelt

This role requires Ansible 2.0 or higher. Requirements are listed in the metadata file.

Please install avisdk from pip prior to running this module.


pip install avisdk --upgrade

Installation

To install the AviSDK Ansible Module, please issue the command on the machine you will run Ansible from.


ansible-galaxy install -f avinetworks.avisdk

For more information please visit http://docs.ansible.com/ansible/galaxy.html

Role Variables

Example Playbooks

The following example is generic, applies to any module.

---
- hosts: localhost
  connection: local
  roles:
    - role: avinetworks.avisdk
  tasks:
    - avi_<module_name>:
      controller: 10.10.27.90
      username: admin
      password: password
      ......

This example shows usage of the avi_healthmonitor module included in this role.

---
- hosts: localhost
  connection: local
  roles:
    - role: avinetworks.avisdk
  tasks:
    - avi_healthmonitor:
        controller: 10.10.27.90
        username: admin
        password: password
        api_version: 17.1
        https_monitor:
          http_request: HEAD / HTTP/1.0
          http_response_code:
            - HTTP_2XX
            - HTTP_3XX
        receive_timeout: 4
        failed_checks: 3
        send_interval: 10
        successful_checks: 3
        type: HEALTH_MONITOR_HTTPS
        name: MyWebsite-HTTPS

There are many more examples located at https://github.com/avinetworks/devops/tree/master/ansible and also available in the "EXAMPLES" within each module.

License

Apache 2.0

Author Information

Avi Networks Avi Networks

ansible-role-avisdk's People

Contributors

amolopcito avatar chaitanyaavi avatar chaitanyadeshpande avatar chandanapatnala avatar ericsysmin avatar gitshrikant avatar karthikvas avatar khaltore avatar luannt8x avatar manojkumarjain avatar patilshrikant486 avatar patilshrikant786 avatar rohan-sss1 avatar sabandi avatar shounak-opcito avatar squirrelala avatar yograjshisode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-avisdk's Issues

Problem with 17.2.2 avi_api_session

Hi All,

We ran into a problem when using the 17.2.2 version of avi_api_session the line here doesn't work with the most recent version of avisdk available from PyPI (17.2.2) because dist.utils.LooseVersion says that "17.2.2" < "17.2.2b5".

When using this module with the newest version of avisdk from PyPI and the avisdk ansible role we get an error and the message that the avisdk is not installed.

When inspecting some of the other modules from the same commit (here and here) it seems they check against "17.1"

Unable to import .... due to more than 255 arguments

Hi,

We have encountered the below error when we tried to use "avi_serviceenginegroup" with ansible-role-avisdk version 20.1.6 , this problem doesn't appear on 20.1.5 .

{
  "msg": "Unable to import avi_serviceenginegroup due to more than 255 arguments", 
  "_ansible_no_log": false
}

Based to this commit 81b4ab8#diff-6a3b6c4711b1eb94c752489c7b99560f57058704226a9fe02df92788d56604fd the library/avi_serviceenginegroup.py has more than 255 arguments.

Multiple runs made in different environments using ansible 2.8 with python 2.7

ansible-playbook 2.8.20
  config file = /go-agent/pipelines/ie2lab_avic_lab/ansible.cfg
  configured module search path = [u'/usr/local/ansible/modules/core', u'/usr/local/ansible/modules/extra', u'/usr/share/ansible', u'/go-agent/pipelines/ie2lab_avic_lab/library']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.18 (default, May  3 2020, 22:58:11) [GCC 8.3.0]
Using /go-agent/pipelines/ie2lab_avic_lab/ansible.cfg as config file

It is possible to look over it and apply a fix for python >= 2.6 ?

Import issue in avi_vsdatascriptset.py

In attempting to use the most recent version of the avinetworks.avisdk role with an avisdk library version we received the error:

Traceback (most recent call last):
  File \"/tmp/ansible_Nbf52b/ansible_module_avi_vsdatascriptset.py\", line 163, in <module> main()
  File \"/tmp/ansible_Nbf52b/ansible_module_avi_vsdatascriptset.py\", line 152, in main
    argument_specs.update(avi_common_argument_spec())
NameError: global name 'avi_common_argument_spec' is not defined"

It seems in the module that it attempts a try here on a series of imports in order to determine if the avisdk python library is installed and if not sets HAS_AVI=False. However, here it attempts to use one of those imports avi_common_argument_spec before it checks the value of HAS_AVI leading to the error seen above.

We were able to resolve this problem by upgrading our avisdk library version in the process but wanted to make you aware of the possible compatibility issue.

Checking if avisdk python library is present breaks in virtual environments

The following change, introduced in 17.2.2, which adds a check for the avisdk package, does not work in a virtual environment, due to an absolute path being used for the python executable.

da32139#diff-2444ad0870f91f17ca6c2a5e96b26823

Steps to reproduce (sort of):
virtualenv venv . venv/bin/activate pip install avisdk python -c 'from avi.sdk.avi_api import ApiSession' # works /usr/bin/python -c 'from avi.sdk.avi_api import ApiSession' # fails

Changing /usr/bin/python to python in tasks/main.yml results in success with a virtual environment.

Issues in avi_customipamdnsprofile when using PATCH operations

When attempting to use the avi_customipamdnsprofile module using PATCH operations (see example below), there seems to be an issue and I think it's an API-level issue.

Environment:
AVISDK role version: 21.1.2
AVI Controller version: 20.1.6
Ansible version: 2.12.1

Here is a playbook.yml YAML file that can be used to reproduce the issue:

---
- hosts: localhost
  connection: local
  gather_facts: no
  vars:
    nsx_alb_host: 10.100.135.202
    nsx_alb_username: admin
    nsx_alb_password: VMware1!
    nsx_alb_api_version: 20.1.6
    nsx_alb_ipam_profile_name: tkg-vip-ipam-profile
    nsx_alb_new_network_ref: "https://10.100.135.202/api/network/dvportgroup-8014-cloud-56603465-9252-4cbe-9304-69a365cd9538"
  tasks:
    - name: Update IPAM Profile Usable Networks
      avi_ipamdnsproviderprofile:
        controller: "{{ nsx_alb_host }}"
        username: "{{ nsx_alb_username }}"
        password: "{{ nsx_alb_password }}"
        api_version: "{{ nsx_alb_api_version }}"
        avi_api_update_method: patch
        avi_api_patch_op: add
        name: "{{ nsx_alb_ipam_profile_name }}"
        type: IPAMDNS_TYPE_INTERNAL
        internal_profile:
          usable_networks:
            - nw_ref: "{{ nsx_alb_new_network_ref }}"

The returned error message:

('HTTP Error: 400 Error Msg {\"error\": \"Failed to patch list of sub objects. Key not found.\"}

**After investigating this, I don't think it's an Ansible issue.
I've tried to invoke the same operation using Postman (but obviously you can see the issue from any REST API client) and got the same error message.

The following can be used to reproduce the issue using Postman:

Request method: PATCH
Request URL: https://{{ nsx_alb_host }}/api/ipamdnsproviderprofile/{{ ipam_profile_uuid }}

Request headers:X-Avi-Version: 20.1.6, Content-Type: application/json

Request body (replace with your network ref object URL):

{
    "add": {
        "internal_profile": {
            "usable_networks": [
                {
                    "nw_ref": "https://10.100.135.202/api/network/dvportgroup-8014-cloud-56603465-9252-4cbe-9304-69a365cd9538"
                }
            ]
        }
    }
}

The returned error in Postman:

Status: 400 BAD REQUEST
{
    "error": "Failed to patch list of sub objects. Key not found."
}

The strange thing is, if you run the same request with the following body (omitting the internal_profile field):

{
    "add": {
        "usable_networks": [
            {
                "nw_ref": "https://10.100.135.202/api/network/dvportgroup-8014-cloud-56603465-9252-4cbe-9304-69a365cd9538"
            }
        ]
    }
}

You will receive status code 200 and response containing the IPAM Profile JSON object although nothing has actually changed... Same thing for delete or replace operations using PATCH.

Reference:
HTTP PATCH support: https://avinetworks.com/docs/20.1/api-http-patch-support
Avi IpamDnsProviderProfile Object API: https://avinetworks.com/docs/latest/api-guide/IpamDnsProviderProfile/index.html

As a temporary workaround, I retrieved the current IPAM Profile JSON object, appended the relevant network refs to the usable_networks array, and used a PUT request. However, it would be much better to be able to use your module to natively add the networks instead of having to use JSON manipulation for this purpose...

My workaround:

---
- hosts: localhost
  connection: local
  gather_facts: no
  vars:
    nsx_alb_host: 10.100.135.202
    nsx_alb_username: admin
    nsx_alb_password: VMware1!
    nsx_alb_api_version: 20.1.6
    nsx_alb_ipam_profile_name: tkg-vip-ipam-profile
    nsx_alb_new_network_name: tkg-wld-01-controlplane
  tasks:
    - name: Get NSX ALB IPAM Profile
      uri:
        url: "https://{{ nsx_alb_host }}/api/ipamdnsproviderprofile?name={{ nsx_alb_ipam_profile_name }}"
        validate_certs: no
        url_username: "{{ nsx_alb_username }}"
        url_password: "{{ nsx_alb_password }}"
        force_basic_auth: yes
        method: GET
        return_content: yes
        headers:
          Content-Type: application/json
          X-Avi-Version: "{{ nsx_alb_api_version }}"
      register: nsx_alb_ipam_profile

    - name: Set Fact - NSX ALB IPAM Profile JSON Object
      set_fact:
       ipam_profile_json: "{{ nsx_alb_ipam_profile.json.results[0] }}"

    - name: Get NSX ALB Network Object
      uri:
        url: "https://{{ nsx_alb_host }}/api/network?name={{ nsx_alb_new_network_name }}"
        validate_certs: no
        url_username: "{{ nsx_alb_username }}"
        url_password: "{{ nsx_alb_password }}"
        force_basic_auth: yes
        method: GET
        return_content: yes
        headers:
          Content-Type: application/json
          X-Avi-Version: "{{ nsx_alb_api_version }}"
      register: nsx_alb_network

    - name: Set Fact - NSX ALB Network Object URL
      set_fact:
        ipam_profile_json_addition:
          internal_profile:
            usable_networks:
              - nw_ref: "{{ nsx_alb_network.json.results[0].url }}"

    - name: Set Fact - Update NSX ALB IPAM Profile JSON Object
      set_fact:
        ipam_profile_json: "{{ ipam_profile_json | combine(ipam_profile_json_addition, recursive=true, list_merge='append_rp') }}"

    - name: Update NSX ALB IPAM Profile
      uri:
        url: "https://{{ nsx_alb_host }}/api/ipamdnsproviderprofile/{{ ipam_profile_json.uuid }}"
        validate_certs: no
        url_username: "{{ nsx_alb_username }}"
        url_password: "{{ nsx_alb_password }}"
        force_basic_auth: yes
        method: PUT
        body: "{{ ipam_profile_json }}"
        body_format: json
        return_content: yes
        headers:
          Content-Type: application/json
          X-Avi-Version: "{{ nsx_alb_api_version }}"

I have also tried AVI controller version 21.1.2 and encountered the same issue.

Password required error even on unauthenticated endpoint

FAILED - RETRYING: Wait for controller cluster modifications (120 retries left).Result was: {
    "attempts": 1,
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/eanderson/.ansible/tmp/ansible-tmp-1559767720.63-3958793335774/AnsiballZ_avi_api_session.py\", line 114, in <module>\n    _ansiballz_main()\n  File
 \"/home/eanderson/.ansible/tmp/ansible-tmp-1559767720.63-3958793335774/AnsiballZ_avi_api_session.py\", line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/eanderson/.
ansible/tmp/ansible-tmp-1559767720.63-3958793335774/AnsiballZ_avi_api_session.py\", line 49, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_avi_api_session_payload_tZCh0S/
__main__.py\", line 249, in <module>\n  File \"/tmp/ansible_avi_api_session_payload_tZCh0S/__main__.py\", line 150, in main\n  File \"/usr/local/lib/python2.7/dist-packages/avi/sdk/avi_api.py\", line 427, in get_session\
n    max_api_retries=max_api_retries)\n  File \"/usr/local/lib/python2.7/dist-packages/avi/sdk/avi_api.py\", line 284, in __init__\n    self.authenticate_session()\n  File \"/usr/local/lib/python2.7/dist-packages/avi/sdk
/avi_api.py\", line 455, in authenticate_session\n    raise APIError(\"Neither user password or token provided\")\navi.sdk.avi_api.APIError: ('Neither user password or token provided', None)\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "retries": 121
}

avi_api_session shouldn't always need user and password as some api's are not authenticated.
ex. path: /api/cluster/runtime

NameError: global name 'avi_common_argument_spec' is not defined

On macOS Using AnsiballZ_avi_healthmonitor.py is throwing this error:

<127.0.0.1> EXEC /bin/sh -c '/usr/local/opt/python@2/bin/python2.7 /Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi
_healthmonitor.py && sleep 0'
36498 1546636878.39933: opening command with Popen()
36498 1546636878.40287: done running command with Popen()
36498 1546636878.40318: getting output with communicate()
36498 1546636878.49552: done communicating
36498 1546636878.49560: done with local.exec_command()
36498 1546636878.49575: _low_level_execute_command() done: rc=1, stdout=, stderr=Traceback (most recent call last):
File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 113, in
_ansiballz_main()

File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 48, in invoke_module
imp.load_module('main', mod, module, MOD_DESC)
File "/var/folders/nf/dfwgrk2s7zq2qmz9wy4d8q18nsnvjz/T/ansible_avi_healthmonitor_payload_ze3noB/main.py", line 213, in
File "/var/folders/nf/dfwgrk2s7zq2qmz9wy4d8q18nsnvjz/T/ansible_avi_healthmonitor_payload_ze3noB/main.py", line 201, in main
NameError: global name 'avi_common_argument_spec' is not defined

36459 1546636878.51350: getting the next task for host localhost
36459 1546636878.51357: done getting next task for host localhost
36459 1546636878.51361: ^ task is: None
36459 1546636878.51368: ^ state is: HOST STATE: block=3, task=8, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_TASKS, pending_se
tup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
The full traceback is:
Traceback (most recent call last):
File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 113, in

_ansiballz_main()

File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 48, in invoke_module
imp.load_module('main', mod, module, MOD_DESC)
File "/var/folders/nf/dfwgrk2s7zq2qmz9wy4d8q18nsnvjz/T/ansible_avi_healthmonitor_payload_ze3noB/main.py", line 213, in
File "/var/folders/nf/dfwgrk2s7zq2qmz9wy4d8q18nsnvjz/T/ansible_avi_healthmonitor_payload_ze3noB/main.py", line 201, in main
NameError: global name 'avi_common_argument_spec' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi
_healthmonitor.py", line 113, in \n _ansiballz_main()\n File "/Users/123223/.ansible/tmp/ansible-tmp-1546636878.27-257638194948148/Ansi
ballZ_avi_healthmonitor.py", line 105, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/Users/123223/.ansib
le/tmp/ansible-tmp-1546636878.27-257638194948148/AnsiballZ_avi_healthmonitor.py", line 48, in invoke_module\n imp.load_module('main', mod, modul
e, MOD_DESC)\n File "/var/folders/nf/dfwgrk2s7zq2qmz9wy4d8q18nsnvjz/T/ansible_avi_healthmonitor_payload_ze3noB/main.py", line 213, in \n
File "/var/folders/nf/dfwgrk2s7zq2qmz9wy4d8q18nsnvjz/T/ansible_avi_healthmonitor_payload_ze3noB/main.py", line 201, in main\nNameError: global na
me 'avi_common_argument_spec' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1

ansible-galaxy list

  • avinetworks.avise-csp, 18.1.3
  • avinetworks.avise, 18.1.5
  • avinetworks.avisdk, 18.2.1
  • avinetworks.aviconfig, 18.1.5
  • avinetworks.avicontroller-csp, 18.1.3
  • avinetworks.avicontroller-vmware, 18.1.3
  • avinetworks.avicontroller-azure, 18.1.3
  • avinetworks.avicontroller, 18.1.5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.