diff --git a/.github/workflows/ansible--uptime.yml b/.github/workflows/ansible--uptime.yml new file mode 100644 index 00000000..05a708c6 --- /dev/null +++ b/.github/workflows/ansible--uptime.yml @@ -0,0 +1,60 @@ +name: Ansible -- Uptime +on: + workflow_dispatch: + inputs: + hosts: + description: 'The value for the variable hosts argument' + required: true + default: 'none' + + verbosity: + description: 'The verbosity level for logs' + required: true + type: choice + default: '' + options: + - '-v' + - '-vv' + - '-vvv' + +jobs: + run_playbook: + runs-on: ubuntu-latest + env: + WORKING_DIR: './ansible' + LINODE_API_TOKEN: ${{ secrets.LINODE_TOKEN }} + + steps: + - name: Checkout + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + + - name: Set up Python 3 + uses: actions/setup-python@v3 + with: + python-version: '3.11' + + - name: Setup pip + run: | + python -m pip install --upgrade pip + + - name: Install Ansible and other dependencies + working-directory: ${{ env.WORKING_DIR }} + run: | + make install + + - name: Ansible Inventory + working-directory: ${{ env.WORKING_DIR }} + run: | + ansible-inventory --graph -v + + - name: Tailscale + uses: tailscale/github-action@v2 + with: + oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} + oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} + tags: tag:ci + + - name: Ansible Playbook + working-directory: ${{ env.WORKING_DIR }} + run: | + ansible-playbook play-any--uptime.yml -e "variable_hosts=${{ github.event.inputs.hosts }}" ${{ github.event.inputs.verbosity }} diff --git a/ansible/Makefile b/ansible/Makefile index 0f634d48..6a4b2cc1 100644 --- a/ansible/Makefile +++ b/ansible/Makefile @@ -15,7 +15,7 @@ help: install: pip install ansible ansible-lint pip install -r requirements/python.txt - ansible-galaxy install -r requirements/roles.yml + # ansible-galaxy install -r requirements/roles.yml ansible-galaxy collection install -r requirements/collections.yml .PHONY: check-linode-env-token diff --git a/ansible/play-any--uptime.yml b/ansible/play-any--uptime.yml index 4680a0bf..59b280cb 100644 --- a/ansible/play-any--uptime.yml +++ b/ansible/play-any--uptime.yml @@ -1,11 +1,10 @@ --- - name: Check uptime on virtual machines - hosts: '{{ variable_host | default("all") }}' + hosts: '{{ variable_host | default("none") }}' gather_facts: true become_user: root + serial: '{{ variable_serial | default(1) }}' tasks: - name: Print uptime debug: - msg: - 'Host machine {{ inventory_hostname }} has been up for {{ - ansible_facts.uptime_seconds/86400 }} days' + msg: 'Host machine {{ inventory_hostname }} has been up for {{ ansible_facts.uptime_seconds/86400 }} days'