THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

Ansible : add alias to an existing host record

New Member
Posts: 1
4504     1

Hello,

 

I'm able to create a host with an alias using Ansible (based on api rest nios_host_record).

For example, following playbook works perfectly :

tasks:
    - name: configure an ipv4 host record
      nios_host_record:
        name: HOST-NAME
        ipv4:
          - address: IP-ADDRESS
        aliases:
          - HOST-ALIAS
        state: present
        view: "myView"
        provider: "{{nios_provider}}"

 

Now, I have a host created (with 0, 1 or N aliases) and I just want to add a new alias to this host.

The problem is I don't find how to do it.

If I use the same code and only change "HOST-ALIAS" (to put a new one) ansible says that "HOST-NAME" already exists and generate an error (because nios_host_record wants to create a host record).

 

So how can I simply create a new alias for an existing host record ?

 

Thank you.

Re: Ansible : add alias to an existing host record

New Member
Posts: 1
4504     1

Hello, were you able to solve this. I am facing the same problem.

Re: Ansible : add alias to an existing host record

[ Edited ]
New Member
Posts: 1
4504     1

For anyone that is interested in how to do this, the below examples are provided for before/after Ansible collections. At least this is what I had discovered.

To run this, you would just need to provide the two extra variables during runtime.
host_record
host_alias

---
- name: host alias management
  hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    # ALIAS - Ansible 2.9 not using collections
    # Fetching the host record IP is required for this nios module prior to collections as it is required for modifying host records
    - name: fetch host record
      set_fact:
        host: "{{ lookup('nios', 'record:host', filter={'name': host_record}, provider=nios_provider) }}"

    - name: print host record ip address
      debug:
        var: host.ipv4addrs[0].ipv4addr

    - name: add alias on existing host record
      nios_host_record:
        name: "{{ host_record }}"
        ipv4:
          - address: '{{ host.ipv4addrs[0].ipv4addr }}'
        aliases:
          - "{{ host_alias }}"
        state: present
        provider: "{{ nios_provider }}"

    # # ALIAS - Ansible 2.10+ using collections
    # - name: add alias on existing host record
    #   community.general.nios_host_record:
    #     name: "{{ host_record }}"
    #     aliases:
    #       - "{{ host_alias }}"
    #     state: present
    #     provider: "{{ nios_provider }}"

Re: Ansible : add alias to an existing host record

New Member
Posts: 3
4505     1
Hi Team,

Add host alias is working as expected. Can you also let us know what to do if we want to remove only alias from that host records
Thanks
Showing results for 
Search instead for 
Did you mean: 

Recommended for You