ansible: reload /etc/resolv.conf for each task.
The OpenShift installer modifies /etc/resolv.conf then tests the new resolver configuration, however, there was no mechanism to reload resolv.conf in our reuseable interpreter. https://github.com/openshift/openshift-ansible/blob/release-3.9/roles/openshift_web_console/tasks/install.yml#L137 This inserts an explicit call to res_init() for every new style invocation, with an approximate cost of ~1usec on Linux since glibc verifies resolv.conf has changed before reloading it. There is little to be done for users of the thread-safe resolver APIs, their state is hidden from us. If bugs like that manifest, whack-a-mole style 'del sys.modules[thatmod]' patches may suffice.pull/245/head
parent
c00e7ed367
commit
2ad0d0521d
@ -0,0 +1,2 @@
|
||||
|
||||
- import_playbook: resolv_conf.yml
|
@ -0,0 +1,38 @@
|
||||
|
||||
# This cannot run against localhost, it damages /etc
|
||||
|
||||
- name: integration/glibc_caches/resolv_conf.yml
|
||||
gather_facts: true
|
||||
become: true
|
||||
hosts: test-targets
|
||||
vars:
|
||||
ansible_become_pass: has_sudo_pubkey_password
|
||||
tasks:
|
||||
|
||||
- debug: msg={{hostvars}}
|
||||
- mitogen_test_gethostbyname:
|
||||
name: www.google.com
|
||||
register: out
|
||||
when: ansible_virtualization_type == "docker"
|
||||
|
||||
- shell: cp /etc/resolv.conf /tmp/resolv.conf
|
||||
when: ansible_virtualization_type == "docker"
|
||||
|
||||
- shell: echo > /etc/resolv.conf
|
||||
when: ansible_virtualization_type == "docker"
|
||||
|
||||
- mitogen_test_gethostbyname:
|
||||
name: www.google.com
|
||||
register: out
|
||||
ignore_errors: true
|
||||
when: ansible_virtualization_type == "docker"
|
||||
|
||||
- shell: cat /tmp/resolv.conf > /etc/resolv.conf
|
||||
when: ansible_virtualization_type == "docker"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- out.failed
|
||||
- '"Name or service not known" in out.msg or
|
||||
"Temporary failure in name resolution" in out.msg'
|
||||
when: ansible_virtualization_type == "docker"
|
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# I am a module that indirectly depends on glibc cached /etc/resolv.conf state.
|
||||
|
||||
import socket
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec={'name': {'type': 'str'}})
|
||||
try:
|
||||
module.exit_json(addr=socket.gethostbyname(module.params['name']))
|
||||
except socket.error, e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue