# Copyright 2022 Google LLC
#
# 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: Configure HTCondor Autoscaler
  hosts: all
  vars:
    python: /usr/local/htcondor/bin/python3
    autoscaler: /usr/local/htcondor/bin/autoscaler.py
  become: true
  tasks:
  - name: User must supply HTCondor role
    ansible.builtin.assert:
      that:
      - project_id is defined
      - region is defined
      - zone is defined
      - mig_id is defined
      - max_size is defined
  - name: Run autoscaler periodically
    # this defaults to * for every time unit
    ansible.builtin.cron:
      name: "run HTCondor autoscaler"
      user: condor
      job: "{{ python }} {{ autoscaler}} --p {{ project_id }} --r {{ region }} --z {{ zone }} --mz --g {{ mig_id }} --c {{ max_size}} | /bin/logger"

# Copyright 2022 Google LLC
#
# 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.

# This playbook makes the assumption that a virtual environment has been created
# with the autoscaler and its dependencies previously installed. A runner that
# does this is provided as an output of the htcondor-install module within the
# HPC Toolkit at community/modules/scripts/htcondor-install.

---
- name: Configure HTCondor Autoscaler
  hosts: all
  vars:
    python: /usr/local/htcondor/bin/python3
    autoscaler: /usr/local/htcondor/bin/autoscaler.py
  become: true
  tasks:
  - name: User must supply HTCondor role
    ansible.builtin.assert:
      that:
      - project_id is defined
      - region is defined
      - zone is defined
      - mig_id is defined
      - max_size is defined
  - name: Run autoscaler periodically
    # this defaults to * for every time unit
    ansible.builtin.cron:
      name: "run HTCondor autoscaler"
      user: condor
      job: "{{ python }} {{ autoscaler}} --p {{ project_id }} --r {{ region }} --z {{ zone }} --mz --g {{ mig_id }} --c {{ max_size}} | /bin/logger"

Add comment to playbook re: pre-installation of Python virtual environment
Add comment to playbook re: pre-installation of Python virtual environment
