Skip to content

Commit

Permalink
Merge pull request #81 from MattKobayashi/yancobat
Browse files Browse the repository at this point in the history
Fix incorrect initial SSH username
  • Loading branch information
MattKobayashi authored Aug 7, 2023
2 parents a1e399a + 8894a33 commit 5bfcb2b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 33 deletions.
14 changes: 7 additions & 7 deletions yancobat/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ FROM alpine:3
WORKDIR /ansible

ARG TARGETPLATFORM
ENV SUPERCRONIC_SHA1SUM_amd64=642f4f5a2b67f3400b5ea71ff24f18c0a7d77d49 \
SUPERCRONIC_SHA1SUM_arm=4f625d77d2f9a790ea4ad679d0d2c318a14ec3be \
SUPERCRONIC_SHA1SUM_arm64=0b658d66bd54cf10aeccd9bdbd95fc7d9ba84a61 \
SUPERCRONIC_SHA1SUM_i386=1b5ebdd122b05cd2ff38b585022f1d909b0146ff \
SUPERCRONIC_VERSION=v0.2.25
ENV SUPERCRONIC_SHA1SUM_amd64=7a79496cf8ad899b99a719355d4db27422396735 \
SUPERCRONIC_SHA1SUM_arm=d8124540ebd8f19cc0d8a286ed47ac132e8d151d \
SUPERCRONIC_SHA1SUM_arm64=e4801adb518ffedfd930ab3a82db042cb78a0a41 \
SUPERCRONIC_SHA1SUM_i386=bcc522ec4ead6de0d564670f6499a88e35082d1f \
SUPERCRONIC_VERSION=v0.2.26

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then ARCH=amd64; elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then ARCH=arm; elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then ARCH=arm64; elif [ "$TARGETPLATFORM" = "linux/i386" ]; then ARCH=i386; else exit 1; fi \
&& export SUPERCRONIC="supercronic-linux-${ARCH}" \
Expand All @@ -31,8 +31,8 @@ USER ansible

COPY --chown=ansible --chmod=0744 entrypoint.sh /ansible/entrypoint.sh
COPY --chown=ansible ansible-cron /ansible/crontab/ansible-cron
COPY --chown=ansible config-backup.yaml /ansible/config-backup.yaml
COPY --chown=ansible clone-repo.yaml /ansible/clone-repo.yaml
COPY --chown=ansible yancobat-backup.yaml /ansible/yancobat-backup.yaml
COPY --chown=ansible yancobat-setup.yaml /ansible/yancobat-setup.yaml
COPY --chown=ansible vars.yaml /ansible/vars.yaml

ENV TZ=UTC \
Expand Down
2 changes: 1 addition & 1 deletion yancobat/ansible-cron
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0 */15 * * * * * ansible-playbook --diff -i /ansible/vars.yaml -i /repo/hosts.yaml config-backup.yaml
0 */15 * * * * * ansible-playbook --diff -i /ansible/vars.yaml -i /repo/hosts.yaml yancobat-backup.yaml
23 changes: 0 additions & 23 deletions yancobat/clone-repo.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion yancobat/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ if [ -f /run/secrets/NOTIFY_SLACK_TOKEN ]; then
export NOTIFY_SLACK_TOKEN=$(cat /run/secrets/NOTIFY_SLACK_TOKEN)
fi

ansible-playbook -i /ansible/vars.yaml /ansible/clone-repo.yaml
ansible-playbook -i /ansible/vars.yaml /ansible/yancobat-setup.yaml
exec supercronic /ansible/crontab/ansible-cron
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
- type: section
text:
type: mrkdwn
text: "A network configuration backup failure has occurred.\n\nPlease check the status of `ansible-network-backup` and rectify any issues."
text: "A network configuration backup failure has occurred.\n\nPlease check the logs and rectify any issues."
- type: divider
- type: context
elements:
Expand Down
86 changes: 86 additions & 0 deletions yancobat/yancobat-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
- name: Clone/update Git repository
hosts: localhost

tasks:
- name: Clone/update Git repository
ansible.builtin.git:
repo: https://{{ github_token }}@github.com/{{ github_repo }}
dest: /repo/

- name: Configure Git username
community.general.git_config:
repo: /repo/
name: user.name
scope: local
value: "{{ git_user }}"

- name: Configure Git user email
community.general.git_config:
repo: /repo/
name: user.email
scope: local
value: "{{ git_email }}"

- name: Configure inventory file
hosts: localhost
gather_facts: false

tasks:
- block:
- name: Set device username/password
ansible.builtin.shell: |
yq -i '.all.children.*.vars.ansible_user = "{{ device_user }}"' /repo/hosts.yaml
yq -i '.all.children.*.vars.ansible_ssh_pass = "{{ device_pass }}"' /repo/hosts.yaml
rescue:
- name: Set failure flag
ansible.builtin.shell:
export FAILURE=true

- name: Failure notifications
hosts: localhost
gather_facts: false
vars:
failure_detected: "{{ lookup('ansible.builtin.env', 'FAILURE') }}"

tasks:
- name: Send failure notification to Telegram
community.general.telegram:
token: "{{ notify_telegram_token }}"
api_args:
chat_id: "{{ notify_telegram_chat_id }}"
parse_mode: "MarkdownV2"
text: |
*\-\- Warning \-\-*
A network configuration backup failure has occurred\.
Please check the status of ansible\-network\-backup and rectify any issues\.
disable_web_page_preview: true
disable_notification: true
protect_content: true
when:
- notify_telegram_enabled
- failure_detected

- name: Send failure notification to Slack
community.general.slack:
token: "{{ notify_slack_token }}"
channel: "{{ notify_slack_channel_id }}"
blocks:
- type: header
text:
type: plain_text
text: "Warning!"
- type: divider
- type: section
text:
type: mrkdwn
text: "A network configuration backup failure has occurred.\n\nPlease check the logs and rectify any issues."
- type: divider
- type: context
elements:
- type: mrkdwn
text: "This notification brought to you by `ansible-network-backup`"
when:
- notify_slack_enabled
- failure_detected

0 comments on commit 5bfcb2b

Please sign in to comment.