-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved ansible repository, added github actions workflow for gitops
- Loading branch information
Showing
7 changed files
with
138 additions
and
52 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
name: GitOps | ||
|
||
on: | ||
push: | ||
branches: [main, development] | ||
pull_request: | ||
schedule: | ||
- cron: '53 1 */15 * *' | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ghcr.io/secshellnet/ansible-vyos-lint | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Run ansible-lint | ||
run: | | ||
ansible-lint -x yaml[comments],yaml[empty-lines],\ | ||
yaml[new-line-at-end-of-file],yaml[trailing-spaces],\ | ||
var-spacing,command-instead-of-shell,no-changed-when,\ | ||
name[template],args[module] | ||
run: | ||
runs-on: ubuntu-latest | ||
needs: [lint] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
if: vars.ENABLE_GITOPS == '1' | ||
|
||
- name: Prepare environment | ||
if: vars.ENABLE_GITOPS == '1' | ||
run: | | ||
echo "${{ secrets.SSH_KEY }}" > .keys/id_ecdsa | ||
chmod 600 .keys/id_ecdsa | ||
ssh-keygen -f .keys/id_ecdsa -y > .keys/id_ecdsa.pub | ||
echo "${{ secrets.ANSIBLE_KEYS_ALL }}" > .keys/all | ||
git submodule update | ||
ansible-galaxy collection install hetzner.hcloud | ||
/opt/pipx/venvs/ansible-core/bin/python -m pip install -r requirements.txt | ||
# not quiet sure why, but we need this package in this python environment | ||
pip3 install python-dateutil | ||
- name: Run ansible inventory in check mode | ||
if: | | ||
vars.ENABLE_GITOPS == '1' && | ||
github.event_name == 'pull_request' | ||
env: | ||
ANSIBLE_HOST_KEY_CHECKING: false | ||
run: | | ||
ansible-playbook playbook.yaml --check | ||
- name: Deploy ansible inventory | ||
if: | | ||
vars.ENABLE_GITOPS == '1' | ||
&& github.event_name != 'pull_request' | ||
env: | ||
ANSIBLE_HOST_KEY_CHECKING: false | ||
run: | | ||
ansible-playbook playbook.yaml |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
passlib>=1.7.4 |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
- name: "Create low privileged unix user account {{ worker_user }}" | ||
ansible.builtin.user: | ||
name: "{{ worker_user }}" | ||
groups: "sudo" | ||
append: true | ||
shell: "/bin/bash" | ||
become: true | ||
|
||
- name: "Set password for low priviledged unix user account {{ worker_user }}" | ||
ansible.builtin.user: | ||
name: "{{ worker_user }}" | ||
password: "{{ worker_password | password_hash('sha512') }}" | ||
password_lock: no | ||
when: new_server | ||
|
||
- name: "Ensure .ssh directory exists for {{ worker_user }}" | ||
ansible.builtin.file: | ||
state: directory | ||
path: "/home/{{ worker_user }}/.ssh/" | ||
owner: "{{ worker_user }}" | ||
group: "{{ worker_user }}" | ||
mode: "0700" | ||
become: true | ||
|
||
- name: "Copy ssh key of ansible to {{ worker_user }}" | ||
ansible.builtin.copy: | ||
src: ".keys/id_ecdsa.pub" | ||
dest: "/home/{{ worker_user }}/.ssh/authorized_keys" | ||
owner: "{{ worker_user }}" | ||
group: "{{ worker_user }}" | ||
mode: "0600" | ||
become: true |
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