#Using Host File Group Entries for NetApp Clusters

1 messages · Page 1 of 1 (latest)

nocturne vault
#

Hello All,

I'm curious. With my "hosts" file, I have the following entry:

[single]
192.168.10.10 shortname=NAS1-CLUSTER

If I have a playbook I was to run an action against, it will only work if I use the IP address of 192.168.10.10.

vars:
netapp_host: '192.168.10.10'
netapp_username: "{{ netapp_username }}"
netapp_password: "{{ netapp_password }}"

If I change the netapp_host field to either 'single' or '[single]' I receive and error:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error using REST for version, error: Failed to parse: https://[single]/api/cluster. Error using REST for version, status_code: None."}

How do you get the playbook to use the group name instead of only IP? If I have larger groups (I do) I don't want be using single IPs.

nocturne vault
#

Using Host File Group Entries for NetApp Clusters

mellow hamlet
eager gale
#

You can use Ansibles standard inventory feature.
hostname: "{{ inventory_hostname }}"
This way the playbook will run through the whole inventory or group you specify in hosts:. You will have to specify connection: local on playbook or task level. Otherwise ansible will try to SSH into your ONTAP system.

Basic example
`- hosts: groupname
become: false
connection: local
collections:

  • netapp.ontap
    name: ONTAP Facts Test
    module_defaults:
    group/netapp.ontap.netapp_ontap:
    hostname: "{{ inventory_hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    https: true
    validate_certs: true
    tasks:

  • name: Gather Info from filer
    netapp.ontap.na_ontap_rest_info:
    gather_subset:
    - cluster
    register: info_result

  • debug:
    var: info_result`

nocturne vault
#

Thanks guys. In the end I got it to work this way:

#

vars: target_group: single tasks: - name: Select a random host from the target group set_fact: netapp_host: "{{ groups[target_group] | random }}" run_once: true