1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_resolvconf.git synced 2024-08-16 10:09:52 +02:00

try to deploy resolv.conf file

This commit is contained in:
L3D 2021-03-04 15:58:39 +01:00
parent cf9afae10c
commit 7b662dbd39
Signed by: l3d
GPG key ID: CD08445BFF4313D1
4 changed files with 63 additions and 3 deletions

View file

@ -1,3 +1,17 @@
--- ---
resolvconf__mode: '0644'
resolveconf__immutable: false
# example config for /etc/resolv.conf
# resolvconf__nameservers:
# - "1.1.1.1"
# - "9.9.9.10"
# resolvconf__domain: "example.com"
# resolvconf__search:
# - "example.com"
# - "foo.local"
# resolvconf__options:
# - "timeout:2"
# - "rotate"
# should we do a version check? (recomended) # should we do a version check? (recomended)
submodules_versioncheck: false submodules_versioncheck: false

View file

@ -1,3 +1,29 @@
--- ---
- include_tasks: versioncheck.yml - ansible.builtin.include_tasks: versioncheck.yml
when: submodules_versioncheck|bool when: submodules_versioncheck|bool
- name: resolv.conf is ino longer immutable.
become: true
ansible.builtin.file:
path: '/etc/resolv.conf'
attr: '-i'
register: resolv_file
changed_when: "'i' in resolv_file.diff.before.attributes and not resolveconf__immutable"
- name: "Configure resolv.conf"
become: true
ansible.builtin.template:
src: 'templates/resolv.conf.j2'
dest: '/etc/resolv.conf'
mode: "{{ resolvconf__mode }}"
owner: root
group: root
- name: Ensure resolv.conf is immutable.
become: true
ansible.builtin.file:
path: '/etc/resolv.conf'
attr: '+i'
register: resolv_file
changed_when: "'i' not in resolv_file.diff.before.attributes"
when: resolveconf__immutable | bool

20
templates/resolve.conf.j2 Normal file
View file

@ -0,0 +1,20 @@
# {{ ansible_managed }}
# do1jlr.resolvconf
{% if resolvconf__search is defined and resolvconf__search | length > 0 -%}
search {{ resolvconf__search|join(' ') }}
{% endif %}
{% if resolvconf__domain is defined and resolvconf__domain != "" -%}
domain {{ resolvconf__domain }}
{% endif %}
{% for n in resolvconf__nameservers -%}
nameserver {{ n }}
{% endfor %}
{% if resolvconf__sortlist is defined and resolvconf__sortlist | length > 0 %}
{% for s in resolvconf__sortlist -%}
sortlist {{ sl }}
{% endfor %}
{% endif %}
{% if resolvconf__options is defined and resolvconf__options | length > 0 -%}
options {{ resolvconf__options|join(' ') }}
{% endif %}

View file

@ -1,4 +1,4 @@
--- ---
# versionscheck # versionscheck
playbook_version_number: 2 # should be a integer playbook_version_number: 3 # should be a integer
playbook_version_path: 'do1jlr.resolveconf.version' playbook_version_path: 'do1jlr.resolvconf.version'