# Copyright 2019 The Kubernetes Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: add bash_profile
  template:
    dest: /home/builder/.bash_profile
    src: photon_bash_profile
    mode: 0600
    owner: builder
    group: builder

- import_tasks: rpm_repos.yml

- name: Perform a tdnf distro-sync
  command: tdnf distro-sync -y --refresh
  register: distro
  changed_when: '"Nothing to do" not in distro.stderr'

- name: Concatenate the Photon RPMs
  set_fact:
    photon_rpms: "{{ rpms | join(' ') }}"

- name: install baseline dependencies
  command: tdnf install {{ photon_rpms }} -y
  when: photon_rpms != ""

- name: install extra RPMs
  command: tdnf install {{ extra_rpms }} -y
  when: extra_rpms != ""

# Default size of 1G is insufficient when downloading additional components
- name: Increase tmpfs size
  mount:
    path: /tmp
    src: "tmpfs"
    fstype: tmpfs
    opts: "size=5G"
    state: remounted

- name: reset iptables rules input
  replace:
    path: /etc/systemd/scripts/ip4save
    regexp: 'INPUT DROP'
    replace: 'INPUT ACCEPT'

- name: reset ip6tables rules input
  replace:
    path: /etc/systemd/scripts/ip6save
    regexp: 'INPUT DROP'
    replace: 'INPUT ACCEPT'