Configure Docker #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Configure Docker | |
on: | |
workflow_dispatch: | |
secrets: | |
SSH_PRIVATE_KEY: | |
type: string | |
required: true | |
inputs: | |
TARGET_HOST: | |
type: string | |
required: true | |
SSH_PORT: | |
type: string | |
required: false | |
default: 22 | |
SSH_USER: | |
type: string | |
required: false | |
default: "root" | |
ANSIBLE_BECOME_PASS: | |
type: string | |
required: false | |
default: "no-password" | |
jobs: | |
ansible: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Add SSH Keys | |
run: | | |
cat << EOF > devops-key | |
${{ secrets.SSH_PRIVATE_KEY }} | |
EOF | |
- name: Update devops private key permissions | |
run: | | |
chmod 400 devops-key | |
- name: Install Ansible | |
run: | | |
pip install ansible | |
- name: Adding or Override Ansible inventory File | |
run: | | |
cat << EOF > ./inventory.ini | |
[webservers] | |
${{ inputs.TARGET_HOST }} | |
EOF | |
- name: Adding or Override Ansible Config File | |
run: | | |
cat << EOF > ./ansible.cfg | |
[defaults] | |
ansible_python_interpreter='/usr/bin/python3' | |
deprecation_warnings=False | |
inventory=./inventory.ini | |
remote_user="${{ inputs.SSH_USER }}" | |
host_key_checking=False | |
private_key_file = ./devops-key | |
retries=2 | |
remote_port = ${{ inputs.SSH_PORT }} | |
EOF | |
- name: Run main playbook | |
run: | | |
if [ "${{ inputs.ANSIBLE_BECOME_PASS }}" != "no-password" ]; then | |
ANSIBLE_CONFIG=ansible.cfg ansible-playbook --ask-become-pass main.yml | |
else | |
ANSIBLE_CONFIG=ansible.cfg ansible-playbook main.yml | |
fi | |