- name: Pre Run Adjustments
  hosts: undercloud
  tags: init
  gather_facts: no
  become: yes
  any_errors_fatal: true
  tasks:
    - name: Set selinux state
      selinux:
          policy: "targeted"
          state: "{{ install.selinux|default('enforcing') }}"

    - name: Ensure yum presence
      # ... helps with old/middle-aged fedora, possibly not needed
      shell: python -c 'import yum' || (dnf install -y yum yum-utils && ln -snf /usr/bin/yum-deprecated /usr/bin/yum)
      when: ansible_distribution == "Fedora"

    - name: set hostname
      hostname:
          # todo(yfried): this seems highly specific. Refactor this to a more generic use case
          name: "{{ inventory_hostname }}.redhat.local"

    - name: update /etc/hosts with undercloud details
      lineinfile:
          dest: "/etc/hosts"
          line: "127.0.0.1   {{ inventory_hostname }}.redhat.local {{ inventory_hostname }}"
          state: present

- import_playbook: create_user.yml
  tags: user

- name: Pre Run Adjustments
  hosts: undercloud
  tags: init
  gather_facts: no
  become: yes
  any_errors_fatal: true
  tasks:
    - name: Set selinux state
      selinux:
          policy: "targeted"
          state: "{{ install.selinux|default('enforcing') }}"

    - name: Ensure yum presence
      # ... helps with old/middle-aged fedora, possibly not needed
      shell: python -c 'import yum' || (dnf install -y yum yum-utils && ln -snf /usr/bin/yum-deprecated /usr/bin/yum)
      when: ansible_distribution == "Fedora"

    - name: set hostname
      hostname:
          # todo(yfried): this seems highly specific. Refactor this to a more generic use case
          name: "{{ inventory_hostname }}.redhat.local"

    - name: update /etc/hosts with undercloud details
      lineinfile:
          dest: "/etc/hosts"
          line: "127.0.0.1   {{ inventory_hostname }}.redhat.local {{ inventory_hostname }}"
          state: present
          insertbefore: BOF

- import_playbook: create_user.yml
  tags: user

Fix the undercloud hostname in /etc/hosts for tls-everywhere deployments
Fix the undercloud hostname in /etc/hosts for tls-everywhere deployments

Since localhost.localdomain is not allowed/valid for undercloud
deployment and let the ipa enrollment task to fail, this change
allow us to make sure the hostname entry is set before localdomain
in /etc/hosts.

Signed-off-by: Francesco Pantano <e4471f5362e63527847b85ad100e4685bab084fa@redhat.com>
Change-Id: I5ea28e1c2812382d0fad1b22a8878f90af93e151
