
The RHEL suppplied ansible-freeipa RPM package installs the modules at the default ansible module path and not as a collection. This caused problems for the end user. This also changes the linter job to run on CentOS, since the ansible-freeipa package is not available on Ubuntu. This also reverts commit 2cc09a2b68c5b64b35742de91d4e7c0cd73f188c. Reason for revert: We get this error: error={"msg": "template error while templating string: cannot import name 'environmentfilter' from 'jinja2.filters' (/usr/lib/python3.9/site-packages/ansible/_vendor/jinja2/filters.py)\n line 0. String: {{ 'A' if record_value | ansible.utils.ipv4 else 'AAAA' }}"} Change-Id: I7df25fb945da1d98c68fe4113a09afdc2f2c5687
124 lines
4.4 KiB
YAML
124 lines
4.4 KiB
YAML
---
|
|
# Copyright 2020 Red Hat, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
|
|
- name: set forward dns record values
|
|
set_fact:
|
|
record_value: "{{ item.split()[0] }}"
|
|
record_name: "{{ item.split()[1].split('.', 1)[0] }}"
|
|
zone_name: "{{ item.split()[1].split('.', 1)[1] }}"
|
|
when: item.split() | length >= 2 and item.split()[1].split('.') | length >= 2
|
|
|
|
- name: set alternative record values
|
|
set_fact:
|
|
record_value: "no record value"
|
|
record_name: "no record name"
|
|
zone_name: "no record zone name provided"
|
|
when: item.split() | length < 2 or item.split()[1].split('.') | length < 2
|
|
|
|
- name: Notify about not adding entries
|
|
debug:
|
|
msg: |
|
|
"{{ item }}" not added to DNS due to not being managed by us.
|
|
Entries with domains outside of cloud_domain are skipped.
|
|
when: not zone_name is match("^(|.+\.)" + cloud_domain + "$")
|
|
|
|
- name: add entries
|
|
block:
|
|
- name: set record type
|
|
set_fact:
|
|
record_type: "{{ 'A' if record_value| ansible.netcommon.ipv4 else 'AAAA' }}"
|
|
|
|
- name: add dns zone
|
|
ipadnszone:
|
|
name: "{{ zone_name }}"
|
|
become: true
|
|
|
|
- name: Modify or add forward dns
|
|
block:
|
|
- name: try modifying forward dns record
|
|
ipadnsrecord:
|
|
zone_name: "{{ zone_name }}"
|
|
record_name: "{{ record_name }}"
|
|
record_type: "{{ record_type }}"
|
|
a_rec: "{{ record_value }}"
|
|
a_ip_address: ""
|
|
when: record_type == 'A'
|
|
become: true
|
|
|
|
- name: try modifying forward dns record
|
|
ipadnsrecord:
|
|
zone_name: "{{ zone_name }}"
|
|
record_name: "{{ record_name }}"
|
|
record_type: "{{ record_type }}"
|
|
aaaa_rec: "{{ record_value }}"
|
|
aaaa_ip_address: ""
|
|
when: record_type == 'AAAA'
|
|
become: true
|
|
rescue:
|
|
- name: add forward dns record
|
|
ipadnsrecord:
|
|
zone_name: "{{ zone_name }}"
|
|
record_name: "{{ record_name }}"
|
|
record_type: "{{ record_type }}"
|
|
record_value: "{{ record_value }}"
|
|
become: true
|
|
|
|
- name: get reverse record data
|
|
set_fact:
|
|
reverse_addr: "{{ record_value | ipaddr('revdns') }}"
|
|
|
|
- name: set reverse record entries for ipv4
|
|
set_fact:
|
|
reverse_record_zone: "{{ reverse_addr.split('.', tripleo_ipa_ptr_zone_split_ipv4|int)[-1] }}"
|
|
reverse_record_name: "{{ '.'.join(reverse_addr.split('.', tripleo_ipa_ptr_zone_split_ipv4|int)[:-1]) }}"
|
|
when: record_type == 'A'
|
|
|
|
- name: set reverse record entries for ipv6
|
|
set_fact:
|
|
reverse_record_zone: "{{ reverse_addr.split('.', tripleo_ipa_ptr_zone_split_ipv6|int)[-1] }}"
|
|
reverse_record_name: "{{ '.'.join(reverse_addr.split('.', tripleo_ipa_ptr_zone_split_ipv6|int)[:-1]) }}"
|
|
when: record_type == 'AAAA'
|
|
|
|
- name: add reverse record dns zone
|
|
ipadnszone:
|
|
name: "{{ reverse_record_zone }}"
|
|
register: reverse_zone_result
|
|
failed_when: reverse_zone_result.failed and 'already exists in DNS' not in reverse_zone_result.msg
|
|
become: true
|
|
|
|
- name: Modify or add reverse dns record
|
|
block:
|
|
- name: try modifying reverse dns record
|
|
ipadnsrecord:
|
|
zone_name: "{{ reverse_record_zone }}"
|
|
record_name: "{{ reverse_record_name }}"
|
|
record_type: "PTR"
|
|
ptr_rec: "{{ record_name }}.{{ zone_name }}."
|
|
ptr_hostname: ""
|
|
become: true
|
|
rescue:
|
|
- name: add reverse dns record
|
|
ipadnsrecord:
|
|
zone_name: "{{ reverse_record_zone }}"
|
|
record_name: "{{ reverse_record_name }}"
|
|
record_type: "PTR"
|
|
record_value: "{{ record_name }}.{{ zone_name }}."
|
|
register: reverse_record_result
|
|
failed_when: reverse_zone_result.failed and 'already exists in DNS' not in reverse_zone_result.msg
|
|
become: true
|
|
when: zone_name is match("^(|.+\.)" + cloud_domain + "$")
|