---
- name: Update /etc/hosts with freeipa's details
  become: yes
  lineinfile:
      dest: "/etc/hosts"
      line: "{{ freeipa_node_ipaddress }} {{ freeipa_node }}.{{ freeipa_cloud_domain }} {{ freeipa_node }}"
      state: present

- name: Install python novajoin
  become: yes
  package:
      name:  python-novajoin
      state: present

- name: Prepare novajoin to work
  become: yes
  shell: >
      /usr/libexec/novajoin-ipa-setup --principal admin --password {{ freeipa_admin_password }} --server {{ freeipa_node }}.{{ freeipa_cloud_domain }} --realm {{ freeipa_cloud_domain|upper }}
      --domain {{ freeipa_cloud_domain }} --hostname {{ groups['undercloud'][0] }}.{{ freeipa_cloud_domain }} --precreate
  register: novajoin

- name: Edit undercloud.conf
  blockinfile:
      path: ~/undercloud.conf
      backup: yes
      marker: "# {mark} TLS EVERYWHERE SETTINGS -->"
      content: |
          enable_novajoin = True
          ipa_otp = {{ novajoin.stdout }}
          undercloud_hostname = {{ groups['undercloud'][0] }}.{{ freeipa_cloud_domain }}
          undercloud_nameservers = {{ freeipa_node_ipaddress }}
          overcloud_domain_name = {{ freeipa_cloud_domain }}

---
- name: Update /etc/hosts with freeipa's details
  become: yes
  lineinfile:
      dest: "/etc/hosts"
      line: "{{ freeipa_node_ipaddress }} {{ freeipa_node }}.{{ freeipa_cloud_domain }} {{ freeipa_node }}"
      state: present

- name: Install python novajoin
  become: yes
  package:
      name:  python-novajoin
      state: present

- name: Prepare novajoin to work
  become: yes
  shell: >
      /usr/libexec/novajoin-ipa-setup --principal admin --password {{ freeipa_admin_password }} --server {{ freeipa_node }}.{{ freeipa_cloud_domain }} --realm {{ freeipa_cloud_domain|upper }}
      --domain {{ freeipa_cloud_domain }} --hostname {{ groups['undercloud'][0] }}.{{ freeipa_cloud_domain }} --precreate
  register: novajoin

- name: Edit undercloud.conf
  blockinfile:
      path: ~/undercloud.conf
      backup: yes
      insertbefore: '^\[ctlplane-subnet\]'
      marker: "# {mark} TLS EVERYWHERE SETTINGS -->"
      content: |
          enable_novajoin = True
          ipa_otp = {{ novajoin.stdout }}
          undercloud_hostname = {{ groups['undercloud'][0] }}.{{ freeipa_cloud_domain }}
          undercloud_nameservers = {{ freeipa_node_ipaddress }}
          overcloud_domain_name = {{ freeipa_cloud_domain }}

Add tls-everywhere settings before ctlplane-subnet section
Add tls-everywhere settings before ctlplane-subnet section

In the undercloud.conf we have the [DEFAULT] followed by the
[ctlplane-subnet] section. When the tls-everywhere config settings
get added to the undercloud.conf the first time, they get appended
to config and end up in the [ctlplane-subnet] section. With this
the 'openstack undercloud install' has missing information and do
not configure and setup novajoin correct. As a result the overcloud
deploy will fail getting the certificates.

This change adds before statement to add the tls-everywhere settings
before the [ctlplane-subnet] section to end up in [DEFAULT].

Change-Id: I3dfb3b2db5ffef37c3321506c8ed893d4e112f14
