- name: Create dedicated steam user
  user:
    name: steam
    create_home: True

- name: Install dependencies
  yum:
    name: "{{ item }}"
  loop:
  - glibc.i686
  - libstdc++.i686
  - unzip
  - dos2unix
  - patch
  - git
  - tar

- name: Create main Steam directory
  file:
    path: '{{ steam_home }}/Steam'
    state: directory
    owner: steam
    group: steam

- name: Obtain SteamCMD
  get_url:
    url: https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
    dest: '{{ steam_home }}/steamcmd_linux.tar.gz'
    owner: steam
    group: steam
  register: steamcmd_dl

- name: Extract SteamCMD
  unarchive:
    src: '{{ steam_home }}/steamcmd_linux.tar.gz'
    dest: '{{ steam_home }}/Steam'
    remote_src: yes
    owner: steam
    group: steam
# this won't work if SteamCMD is downloaded but install failed
#  when: steamcmd_dl.changed

- name: Add Steam to PATH
  replace:
    path: '{{ steam_home }}/{% if ansible_distribution_major_version == '7' %}.bash_profile{% else %}.bashrc{% endif %}'
    regexp: 'PATH="(.*):\$PATH"$'
    replace: 'PATH="\1:$PATH:$HOME/Steam"'
    owner: steam
    group: steam

- name: Create dedicated steam user
  user:
    name: steam
    create_home: True

- name: Install dependencies
  yum:
    name: "{{ item }}"
  loop:
  - glibc.i686
  - libstdc++.i686
  - unzip
  - dos2unix
  - patch
  - git
  - tar

- name: Create main Steam directory
  file:
    path: '{{ steam_home }}/Steam'
    state: directory
    owner: steam
    group: steam

- name: Obtain SteamCMD
  get_url:
    url: https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
    dest: '{{ steam_home }}/steamcmd_linux.tar.gz'
    owner: steam
    group: steam
  register: steamcmd_dl

- name: Extract SteamCMD
  # owner/group seem to be bugged, use become instead
  become: yes
  become_user: steam
  unarchive:
    src: '{{ steam_home }}/steamcmd_linux.tar.gz'
    dest: '{{ steam_home }}/Steam'
    remote_src: yes
# this won't work if SteamCMD is downloaded but install failed
#  when: steamcmd_dl.changed

- name: Add Steam to PATH
  replace:
    path: '{{ steam_home }}/{% if ansible_distribution_major_version == '7' %}.bash_profile{% else %}.bashrc{% endif %}'
    regexp: 'PATH="(.*):\$PATH"$'
    replace: 'PATH="\1:$PATH:$HOME/Steam"'
    owner: steam
    group: steam

Fix unarchive creating files owned by root despite setting owner/group
Fix unarchive creating files owned by root despite setting owner/group
