diff --git a/.github/workflows/duplicate_check.yml b/.github/workflows/duplicate_check.yml deleted file mode 100644 index 7b972d5..0000000 --- a/.github/workflows/duplicate_check.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Validate Domain Duplication - -on: - push: - branches: - - '**' - -jobs: - Duplicate_Check: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Add exec flag to dupcheck.sh - run: "chmod +x ./dupcheck.sh" - - - name: NXDOMAIN_Duplicate_Check - run: > - "./dupcheck.sh" - "inventories/host_vars/rui/ads_hosts/NXDOMAIN.yml" diff --git a/.github/workflows/jobs.yml b/.github/workflows/jobs.yml new file mode 100644 index 0000000..77f3b81 --- /dev/null +++ b/.github/workflows/jobs.yml @@ -0,0 +1,107 @@ +--- +name: Hayaworld Ansible Jobs +on: + push: + branches: + - '**' + workflow_dispatch: + +jobs: + Yamllint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run YAML Lint + run: yamllint --strict --format github . + + AnsibleLint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Ansible-lint + uses: ansible/ansible-lint@main + + Duplicate_Check: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Add exec flag to dupcheck.sh + run: "chmod +x ./dupcheck.sh" + + - name: NXDOMAIN_Duplicate_Check + run: > + "./dupcheck.sh" + "inventories/host_vars/rui/ads_hosts/NXDOMAIN.yml" + + Detect_File_Changed: + runs-on: ubuntu-latest + outputs: + rui: ${{ steps.changes.outputs.rui }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check What file were changed + uses: dorny/paths-filter@v3 + id: changes + with: + filters: | + rui: + - 'rui.yml' + - 'tasks/rui/dnsmasq.yml' + - 'inventories/host_vars/rui/**' + + Dry_Run_ansible: + if: ${{ needs.Detect_File_Changed.outputs.rui == 'true' }} + needs: + - Yamllint + - AnsibleLint + - Duplicate_Check + - Detect_File_Changed + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare environments (ansible-galaxy) + run: | + ansible-galaxy install -r requirements.yml + + - name: "ansible-playbook -C --tags dnsmasq rui.yml" + run: | + ansible-playbook \ + -i inventories \ + -C \ + --tags dnsmasq \ + --ssh-extra-args='-o StrictHostKeyChecking=no' \ + --extra-vars "ansible_sudo_pass=${{ secrets.SUDO }}" \ + rui.yml + + Run_ansible: + # if file for rui changed and master branch + if: "${{ needs.Detect_File_Changed.outputs.rui == 'true' && github.ref == 'refs/heads/master'}}" + needs: + - Dry_Run_ansible + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare environments (ansible-galaxy) + run: | + ansible-galaxy install -r requirements.yml + + - name: "ansible-playbook --tags dnsmasq rui.yml" + run: | + ansible-playbook \ + -i inventories \ + --tags dnsmasq \ + --ssh-extra-args='-o StrictHostKeyChecking=no' \ + --extra-vars "ansible_sudo_pass=${{ secrets.SUDO }}" \ + rui.yml diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml deleted file mode 100644 index a638b9b..0000000 --- a/.github/workflows/lints.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -name: Lints - -on: - push: - branches: - - '**' - -jobs: - Yamllint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Run YAML Lint - run: yamllint --strict --format github . - - AnsibleLint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Restore pip cache - uses: actions/cache/restore@v4 - with: - path: /home/runner/.cache/pip - key: ansible-hayaworld-pip-cache - - - name: Run Ansible-lint - uses: ansible/ansible-lint@main - - - name: Store pip cache - uses: actions/cache/save@v4 - with: - path: /home/runner/.cache/pip - key: ansible-hayaworld-pip-cache diff --git a/.github/workflows/shellspec.yml b/.github/workflows/shellspec.yml deleted file mode 100644 index ef0fb42..0000000 --- a/.github/workflows/shellspec.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -name: Validate Domain Duplication Shell Unit Test - -on: - push: - paths: - - "**.sh" - -jobs: - Duplicate_Check: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Add exec flag to dupcheck.sh - run: "chmod +x ./dupcheck.sh" - - - name: Get Shellspec - run: "curl -fsSL https://git.io/shellspec | sh -s -- --yes" - - - name: Run Shellspec - run: "~/.local/lib/shellspec/shellspec" diff --git a/inventories/host_vars/rui/test.yml b/inventories/host_vars/rui/test.yml new file mode 100644 index 0000000..60fc2fe --- /dev/null +++ b/inventories/host_vars/rui/test.yml @@ -0,0 +1,3 @@ +--- +a: + - a.yml diff --git a/rui.yml b/rui.yml index 01785bf..ff4483e 100644 --- a/rui.yml +++ b/rui.yml @@ -56,6 +56,8 @@ - name: Setup dnsmask ansible.builtin.import_tasks: file: tasks/rui/dnsmasq.yml + tags: + - dnsmasq - name: Setup journalctl ansible.builtin.import_tasks: diff --git a/tasks/rui/dnsmasq.yml b/tasks/rui/dnsmasq.yml index b49a11d..e26d4c2 100644 --- a/tasks/rui/dnsmasq.yml +++ b/tasks/rui/dnsmasq.yml @@ -7,15 +7,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - -- name: Show dnsmasq.conf - ansible.builtin.debug: - msg: "{{ lookup('template', './templates/rui/etc/dnsmasq.conf.j2') }}" - tags: - - debug - - dryrun - name: Add dnsmasq.resolv.txt ansible.builtin.template: @@ -25,15 +16,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - -- name: Show dnsmasq.resolv.txt - ansible.builtin.debug: - msg: "{{ lookup('template', './templates/rui/etc/dnsmasq.d/resolv.txt.j2') }}" - tags: - - debug - - dryrun - name: Add static DHCP config ansible.builtin.template: @@ -43,15 +25,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - -- name: Show static DHCP config - ansible.builtin.debug: - msg: "{{ lookup('template', './templates/rui/etc/dnsmasq.d/dhcp_static.conf.j2') }}" - tags: - - debug - - dryrun - name: Add cname config ansible.builtin.template: @@ -61,15 +34,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - -- name: Show cname config - ansible.builtin.debug: - msg: "{{ lookup('template', './templates/rui/etc/dnsmasq.d/cname.conf.j2') }}" - tags: - - debug - - dryrun - name: Add NXDOMAIN (Ads Block) config ansible.builtin.template: @@ -79,15 +43,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - -- name: Show cname config - ansible.builtin.debug: - msg: "{{ lookup('template', './templates/rui/etc/dnsmasq.d/blocklist.conf.j2') }}" - tags: - - debug - - dryrun - name: Add hosts(5) ansible.builtin.template: @@ -97,5 +52,3 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq