---
-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Setting hostname"
      ansible.builtin.hostname:
        name: "{{ settings.hostname }}.{{ settings.domain }}"
    
    -
      name: "Gathering facts on current container"
      community.docker.current_container_facts:
    
    -
      name: "Printing information on current container when running in a container"
      ansible.builtin.debug:
        msg: "Container ID is {{ ansible_module_container_id }}"
      when: ansible_module_running_in_container
    
    -
      name: "Setting /etc/hosts"
      when: not ansible_module_running_in_container
      ansible.builtin.replace:
        path: "/etc/hosts"
        regexp: "{{ item.regex }}"
        replace: "{{ item.replace }}"
      with_items:
        - { regex: "(^127.0.0.1)(.*)$", replace: '127.0.0.1   localhost {{ settings.hostname }}.{{ settings.domain }} {{ settings.hostname }}'}
        - { regex: "(^127.0.1.1)(.*)$", replace: '127.0.1.1   localhost {{ settings.hostname }}.{{ settings.domain }} {{ settings.hostname }}'}
