- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Ansible : add alias to an existing host record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 04:54 AM
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.
Solved! Go to Solution.
Re: Ansible : add alias to an existing host record
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2019 03:31 PM
Hello, were you able to solve this. I am facing the same problem.
Re: Ansible : add alias to an existing host record
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2021 08:28 PM - edited 05-05-2021 08:34 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2022 12:28 PM
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