Reputation: 75
Is it possible to customize a IP adress with Ansible. For example when the remote system IP is 127.34.34.21
the DNS IP is 127.34.34.1
The DNS IP is always the system IP but the last number is 1
. Is it possible that Ansible can do this dynamical?
Look up the system IP > Customize it > set the new IP as DNS IP.
Upvotes: 2
Views: 130
Reputation: 68034
Q: "Is it possible to customize an IP address with Ansible?"
A: Yes. It is. There are many options.
- set_fact:
dns: "{{ ip.split('.')[:3]|join('.') ~ '.1' }}"
vars:
ip: 127.34.34.21
- debug:
var: dns
give
dns: 127.34.34.1
- set_fact:
dns: "{{ (ip|splitext)[0] ~ '.1' }}"
- set_fact:
dns: "{{ (ip ~ '/24')|ipaddr('first_usable') }}"
Q: "Is it possible that Ansible can do this dynamical?"
A: Yes. It is. You'll have to decide which IP address to use. For example, use ansible_default_ipv4.address
- debug:
var: ansible_default_ipv4.address
- set_fact:
dns: "{{ (ip ~ '/24')|ipaddr('first_usable') }}"
vars:
ip: "{{ ansible_default_ipv4.address }}"
- debug:
var: dns
give (abridged)
ansible_default_ipv4.address: 10.1.0.27
dns: 10.1.0.1
See setup. See other attributes of the variable ansible_default_ipv4. See variable ansible_all_ipv4_addresses.
Upvotes: 2