HewlettPackard / oneview-ansible-collection

Ansible Collection and Sample Playbooks for HPE OneView
Apache License 2.0
25 stars 22 forks source link

General documentation issues #225

Closed frippe75 closed 1 year ago

frippe75 commented 1 year ago

Hi,

None of the examples shows how to use the new and improved roles. I want to rename and reassing a SP and notice that the role has been rewamped to take the newname property. This is not true for the modules which seems to have been left dragging.

So first question is an ask to have the README show how to perform authentication when using the import_role construct.

Tried:

    - name: (server_profile_template)
      include_role:
        name: hpe.oneview.oneview_server_profile_template
      vars:
        config: "{{ config }}"
      register: msg

Results in: Error was a <class 'ansible.errors.AnsibleError'>, original message: recursive loop detected in template string: {{ config }}"}

Also would be MUCH better allowing us to pass the config JSON as a variable rather than passing the filename. Not a "vault/secret" firnedly construction?

frippe75 commented 1 year ago

renaming the variable from config to config_file resolves the recursion which does not occur using the modules but could be Ansible related.

New error: ERROR! An unhandled exception occurred while templating '{{ lookup('file','../config/config.json') | from_json

The error comes from the defaults file. Is it really mandatory to have that file?

There is a way to handle the possibility of it not being there: https://stackoverflow.com/questions/29039588/how-to-use-lookupfile-in-ansible-when-the-file-might-not-exist

frippe75 commented 1 year ago

Ok... So the Roles are mear examples... had to look into them to figure that out... So I guess the issue is still valid, at least from my perspective.

nabhajit-ray commented 1 year ago

Hi @frippe75 ,

Will check and get back to you

alisha-k-kalladassery commented 1 year ago

Hi Fredrick, Iterating through your questions one by one,

  1. So first question is an ask to have the README show how to perform authentication when using the import_role construct.

To perform authentication , we can either provide the config as json and reference the same as config by providing the path to config.json in defaults.yaml.

Or you can have the config fields in vars and reference the same in your tasks as below.

  - hosts: all

    collections:

      - hpe.oneview

    vars:

      hostname: "host_ip"

      username: "username"

      password: "password"

      api_version: "api_version"

      contents: "{{lookup('file','../config1/config.json', errors='ignore')}}"

    tasks:

      - name: Create a server profile template

        oneview_server_profile_template:

          hostname: "{{ hostname }}"

          username: "{{ username }}"

          password: "{{ password }}"

          api_version: "{{ api_version }}"

          state: present

          data:

            name: "{{ item.name }}"

            serverHardwareTypeName: "{{ contents.server_profile_template.server_hardware_type_name }}"

            enclosureGroupName: "{{ contents.server_profile_template.enclosure_group_name }}"

            connectionSettings:

              manageConnections: true

              complianceControl: "Checked"

          params:

            force: "True" # Supported only for API version >= 600

        delegate_to: localhost

        with_items:

          - { name: '{{ contents.server_profile_template.server_profile_template_name }}' }
  1. ERROR! An unhandled exception occurred while templating '{{ lookup('file','../config/config.json') | from_json

Error was wrt '{{ lookup('file','../config/config.json') | from_json}}'

We are using this config.json as a file to pass any user inputs specific to the module which you are running.

So you can either directly provide the values in playbook as above Or you can have path to config.json({{lookup('file','../config1/config.json', errors='ignore')}}") as contents in vars and use the same in your tasks.

PS: If you are providing module specific inputs in a config.json, below is an example. "server_profile_template":{ "server_profile_template_name": "", "server_hardware_type_name": "", "enclosure_group_name": "", "connection_network_name": ""}

frippe75 commented 1 year ago

@alisha-k-kalladassery, no once it was clear all roles where mere examples and the "product" is still a set of modules I got everything working as expected.

I do believe the authentication part could be worked on. having a cleartext config or give all that logon-context for each play clutters my playbooks. Would be better to get an auth-token and provide that throughout instead.

alisha-k-kalladassery commented 1 year ago

Hi Fredrik,

It is all customisable. If you want to maintain only one config file, you can reference the same in defaults/main.yml of your role. For Eg: config: "~/.ansible/collections/ansible_collections/hpe/oneview/config/oneview_config.json"

oneview_config.json:

{
  "ip": "<oneview_ip>",
  "credentials": {
    "userName": "<user_name>",
    "password": "<password>",
    "authLoginDomain": "<domain_directory>"
},
  "api_version": 4600,
  "variant": "Synergy"
}

And you can use the config var in your playbooks.

- name: Create an Enclosure Group
  oneview_enclosure_group:
    config: "{{ config }}"
    sessionID: "{{ session.ansible_facts.session }}"
    state: present
    data:
        name: "{{ item.name }}"
        ipAddressingMode: "External"
        ipv6AddressingMode: "External"
        enclosureCount: 3
        interconnectBayMappings:
          - interconnectBay: 3
            logicalInterconnectGroupUri: "{{ lig_uri }}"
          - interconnectBay: 6
            logicalInterconnectGroupUri: "{{ lig_uri }}"
  delegate_to: localhost
  with_items:
    - { name: 'EG' }

In this way, you are providing the oneview cred in only one file and using the same in all your roles.

alisha-k-kalladassery commented 1 year ago

Closing this issue as we have not heard from you. Please feel free to get back to us if you face any issues.