Developer

 View Only
last person joined: 3 days ago 

Expand all | Collapse all

ArubaOS Ansible modules

This thread has been viewed 21 times
  • 1.  ArubaOS Ansible modules

    Posted Apr 16, 2020 09:00 AM

    Hi,

     

    If you're interested in automating ArubaOS with ansible, I wrote a set of modules to automate ArubaOS 8 that can help with that.

     

    You can find it on github at:

    https://github.com/sachaboudjema/ansible-modules-arubaos

     

    List of modules

    • arubaos_controller_config: Backward compatibility with playbooks based on the module found at aruba/aruba-ansible-modules
    • arubaos_get: Executes GET operations on API objects
    • arubaos_set: Add, modify or delete configuration
    • arubaos_facts: Populates ansible_facts with sys_info details about the system to which the query is being sent
    • arubaos_config: Queries full or partial configuration of a particular configuration node.
    • arubaos_writememory: Executes a show command on the controller and returns structured data when supported
    • arubaos_showcommand: Commits the pending configuration (if any) on the specified node

     

    Noteworthy features

     

    General

    • Arguments host, username and password support fallback to env variables ANSIBLE_ARUBAOS_HOST, ANSIBLE_ARUBAOS_USERNAME, ANSIBLE_ARUBAOS_PASSWORD to avoid having to repeat them on each module call.

    arubaos_controller_config

    • Provides backwards compatibility with playbooks based on the module found at aruba/aruba-ansible-modules.

    arubaos_get

    • Implements all get modifiers (i.e. filters) supported by the API

    arubaos_set

    • Fully idempotent
    • Support for check_mode and diff
    • Support for normal and mulipart set operation

     

    Example playbook

    Here is an example playbook displaying some of the features provided by these modules:

     

     

     

     

    ---
    - name: "Example playbook for ArubaOS modules"
      hosts: 127.0.0.1
      connection: local
      gather_facts: no
    
      environment:
        ANSIBLE_ARUBAOS_HOST: "{{ mm_ip }}"
        ANSIBLE_ARUBAOS_USERNAME: "{{ mm_username }}"
        ANSIBLE_ARUBAOS_PASSWORD: "{{ mm_password }}"
    
      vars:
        config_path: "/md/branch1/floor1"
    
      tasks:
    
        - name: Gather facts
          arubaos_facts:
          tags: facts
    
        - name: Show command
          arubaos_showcommand:
            command: show switches
          tags: showcommand
    
        - name: Write memory
          arubaos_writememory:
            config_path: "{{ config_path }}"
          tags: writememory
    
        - name: Get Config
          arubaos_config:
            config_path: "{{ config_path }}"
          tags: config
    
        - name: Get Config with type filter
          arubaos_config:
            config_path: "{{ config_path }}"
            type: local
          tags: config
    
        - name: Get objects
          arubaos_get:
            config_path: "{{ config_path }}"
            object: ap_group
          tags: get
    
        - name: Get with sort
          arubaos_get:
            config_path: "{{ config_path }}"
            object: ap_group
            sort: '-id'
          tags: get
    
        - name: Get with pagination
          arubaos_get:
            config_path: "{{ config_path }}"
            object: ap_group
            limit: 2
            offset: 2
            total: 10
          tags: get
    
        - name: Get with object filter
          arubaos_get:
            config_path: "{{ config_path }}"
            object: ap_group
            object_filters:
              - oper: $eq
                values: ['ap_group.ap_sys_prof', 'ap_group.am_filter_prof']
          tags: get
    
        - name: Get with data filter
          arubaos_get:
            config_path: "{{ config_path }}"
            object: ap_group
            data_filters:
              - param_name: 'ap_group.profile-name'
                oper: $in
                values: ['default']
          tags: get
    
        - name: Get with data type filter
          arubaos_get:
            config_path: "{{ config_path }}"
            object: ap_group
            data_types: ['non-default']
          tags: get
    
        - name: Set single object single instance
          arubaos_set:
            config_path: "{{ config_path }}"
            data:
              ap_group:             
                profile-name: "grp-test-ansible-sOsI"
          tags: set
    
        - name: Set single object multiple instance
          arubaos_set:
            config_path: "{{ config_path }}"
            data:
              ap_group: 
                - profile-name: "grp-test-ansible-1"
                - profile-name: "grp-test-ansible-2"
          tags: set
    
        - name: Set & commit single object multiple instance
          arubaos_set:
            config_path: "{{ config_path }}"
            data:
              ap_group: 
                - profile-name: "grp-test-ansible-1"
                - profile-name: "grp-test-ansible-2"
            commit: true
          tags: set
    
        - name: Set multiple object multiple instance
          arubaos_set:
            config_path: "{{ config_path }}"
            data:
              server_group_prof:
                - sg_name: "sg_grp-test_ansible-1"
                - sg_name: "sg_grp-test_ansible-2"
              ap_group: 
                - profile-name: "grp-test-ansible-1"
                - profile-name: "grp-test-ansible-2"
          tags: set
    
        - name: Set multi-part & commit (continue if error)
          arubaos_set:
            config_path: "{{ config_path }}"
            multipart_data:
              - ap_group:
                  profile-name: "grp-test-ansible-3"
              - server_group_prof:
                  - sg_name: "sg_grp-test_ansible-1"
                  - sg_name: "sg_grp-test_ansible-2"
                ap_group: 
                  - profile-name: "grp-test-ansible-1"
                  - profile-name: "grp-test-ansible-2"
            commit_force: true
          tags: set

     

     

     

     

     

    Feedback is of high value to improve code, so don't hesitate.

     

    Enjoy.

     



  • 2.  RE: ArubaOS Ansible modules

    Posted Apr 21, 2020 08:58 AM

    Hi Sacha would try your Ansible modules but how to install them ?

    cloned them from GitHub to folder /usr/share/ansible/plugins/

    and tried a  "ansible-doc -t module ....... " to verify the functionality  

    but only get this error .

     

     ansible-doc -t module arubaos_facts

    ERROR! module arubaos_facts missing documentation (or could not parse documentation): unknown doc_fragment(s) in file /usr/share/ansible/plugins/modules/ansible-modules-arubaos/library/arubaos_facts.py: arubaos

    regards Markus



  • 3.  RE: ArubaOS Ansible modules

    Posted Apr 22, 2020 01:21 AM

    Hi Markus,

     

    The directory structure of the git repo is intended to be imported directly along your playbooks.

     

    You should be able to clone anywhere on your system and execute playbooks and ansible commands within that directory.

     

    If you need to have the modules merged into your ansible system path, the layout of the files would have to be changed a bit.

    I'de glad to provide a script to do that if you could open up an issue on github and give me a some time to work on that.

     

    Cheers, 



  • 4.  RE: ArubaOS Ansible modules

    Posted Apr 22, 2020 05:52 AM

    Hi Markus,

     

    I added installation notes to the README on the master branch.


    Note that I just published the modules to Ansible Galaxy, which provides an easy way to install the modules.

     

    If you need any further help using the modules, you can post it here. I also created a google group for general discussions and help: https://groups.google.com/forum/#!forum/ansible-modules-arubaos



  • 5.  RE: ArubaOS Ansible modules

    Posted Apr 22, 2020 06:29 AM

    HI Sacha

    installed the modules via Ansible galaxy  like you described.

    but still get there error

     

    ERROR! couldn't resolve module/action 'arubaos_showcommand'. This often indicates a misspelling, missing collection, or incorrect module path.

     

    Regards Markus



  • 6.  RE: ArubaOS Ansible modules

    Posted Apr 22, 2020 06:34 AM

    When working with collections you have to specify the fully qualified name of the module, i.e. "sachaboudjema.arubaos.arubaos_showcommand".

     

    Same in your playbooks, except if you add the collection to the 'collections' attribute of the playbook. Check the readme at https://galaxy.ansible.com/sachaboudjema/arubaos.