ansible-freebsd-jailhost-tools/tasks/jail/update_etc_hosts.yml

21 lines
717 B
YAML
Raw Normal View History

# IMPORTANT: after the IP that is 2 TABULATOR character
- name: Getting matching /etc/hosts files
command: >-
/bin/sh -c "/usr/bin/grep -lE
'^[0-9]+.[0-9]+.[0-9]+.[0-9]+ jail_{{ jail_name }}'
/usr/jails/*/etc/hosts {{ dynamic_jails_path }}/*/etc/hosts"
ignore_errors: yes
failed_when: false
register: matching_hosts_files
- name: Replacing appropriate jail names with new IP addresses in /etc/hosts files
lineinfile:
dest: '{{ filename }}'
regexp: '^\d+\.\d+\.\d+\.\d+ jail_{{ jail_name }}'
line: '{{ vars["jail_" + jail_name + "_new_ip"] }} jail_{{ jail_name }}'
state: present
with_items: '{{ matching_hosts_files.stdout_lines }}'
loop_control:
loop_var: filename