---
- hosts: all
  sudo: yes
  tasks:
  - name: Setup /etc/hosts
    copy:
      src: /etc/hosts
      dest: /etc/hosts

  - name: Assign hostname
    hostname:
      name: "{{ inventory_hostname }}"

  - name: Copy setup script
    copy:
      src: setup_{{ ansible_os_family }}.sh
      dest: /tmp/setup.sh
      mode: 0755

- hosts: all
  tasks:
  - name: Create log directory for node
    file:
      state: directory
      path: /tmp/{{ inventory_hostname }}

  - name: Run node setup
    shell: sudo /tmp/setup.sh

  - name: Changing permissions of docker socket to 666
    shell: sudo chmod 0666 /run/docker.sock

---
- hosts: all
  sudo: yes
  tasks:
  - name: Setup /etc/hosts
    copy:
      src: /etc/hosts
      dest: /etc/hosts

  - name: Ensure /etc/hostname is valid for SELinux
    command: restorecon -v /etc/hostname
    when: ansible_os_family == 'RedHat'

  - name: Assign hostname
    hostname:
      name: "{{ inventory_hostname }}"

  - name: Copy setup script
    copy:
      src: setup_{{ ansible_os_family }}.sh
      dest: /tmp/setup.sh
      mode: 0755

- hosts: all
  tasks:
  - name: Create log directory for node
    file:
      state: directory
      path: /tmp/{{ inventory_hostname }}

  - name: Run node setup
    shell: sudo /tmp/setup.sh

  - name: Changing permissions of docker socket to 666
    shell: sudo chmod 0666 /run/docker.sock

Make sure /etc/hostname is valid for SELinux
Make sure /etc/hostname is valid for SELinux

In the gate, it is possible for /etc/hostname to not have a valid
SELinux security conext. So, reset them to default before we update
the hostname to avoid:

  TASK: [Assign hostname]
  failed: [node1] => {"failed": true}
  msg: Command failed rc=1, out=, err=Could not set property: Access
  denied

Closes-Bug: #1568047
Change-Id: Ie30c8437b310d1ea5bc75307375c255131dfe934
Needed-By: I2ff5fbb315832b8cf07c93d0dd0cdaacd958631e
