From 908ab995766bb3a2007f1234bc00ee4083fa0dfe Mon Sep 17 00:00:00 2001 From: cradle8810 Date: Thu, 25 Apr 2024 20:30:34 +0900 Subject: [PATCH 1/4] =?UTF-8?q?dnsmasq=E3=81=AEtask=E3=81=8B=E3=82=89Debug?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/rui/dnsmasq.yml | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/tasks/rui/dnsmasq.yml b/tasks/rui/dnsmasq.yml index b49a11d..36aaaeb 100644 --- a/tasks/rui/dnsmasq.yml +++ b/tasks/rui/dnsmasq.yml @@ -10,13 +10,6 @@ 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: src: templates/rui/etc/dnsmasq.d/resolv.txt.j2 @@ -28,13 +21,6 @@ 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: src: templates/rui/etc/dnsmasq.d/dhcp_static.conf.j2 @@ -46,13 +32,6 @@ 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: src: templates/rui/etc/dnsmasq.d/cname.conf.j2 @@ -64,13 +43,6 @@ 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: src: templates/rui/etc/dnsmasq.d/blocklist.conf.j2 @@ -82,13 +54,6 @@ 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: src: templates/rui/etc/hosts.j2 From 78d4da01ded6b6d6cfe7c0adc61009b555af1e30 Mon Sep 17 00:00:00 2001 From: cradle8810 Date: Thu, 25 Apr 2024 20:31:30 +0900 Subject: [PATCH 2/4] =?UTF-8?q?dnsmasq=E9=96=A2=E9=80=A3=E3=81=AEtask?= =?UTF-8?q?=E3=81=8B=E3=82=89tag=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Playbookに書くべき内容 --- rui.yml | 2 ++ tasks/rui/dnsmasq.yml | 12 ------------ 2 files changed, 2 insertions(+), 12 deletions(-) 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 36aaaeb..e26d4c2 100644 --- a/tasks/rui/dnsmasq.yml +++ b/tasks/rui/dnsmasq.yml @@ -7,8 +7,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - name: Add dnsmasq.resolv.txt ansible.builtin.template: @@ -18,8 +16,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - name: Add static DHCP config ansible.builtin.template: @@ -29,8 +25,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - name: Add cname config ansible.builtin.template: @@ -40,8 +34,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - name: Add NXDOMAIN (Ads Block) config ansible.builtin.template: @@ -51,8 +43,6 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq - name: Add hosts(5) ansible.builtin.template: @@ -62,5 +52,3 @@ group: root mode: '0644' notify: "Restart dnsmasq" - tags: - - dnsmasq From 8cb45ba321bc3695b3b84a4c82466d822a64bba4 Mon Sep 17 00:00:00 2001 From: cradle8810 Date: Thu, 25 Apr 2024 20:40:40 +0900 Subject: [PATCH 3/4] =?UTF-8?q?ansible-playbook=20-C=20=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dnsmasq-exec.yml | 22 ++++++++++ .github/workflows/duplicate_check.yml | 22 ---------- .github/workflows/jobs.yml | 63 +++++++++++++++++++++++++++ .github/workflows/lints.yml | 38 ---------------- .github/workflows/shellspec.yml | 23 ---------- 5 files changed, 85 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/dnsmasq-exec.yml delete mode 100644 .github/workflows/duplicate_check.yml create mode 100644 .github/workflows/jobs.yml delete mode 100644 .github/workflows/lints.yml delete mode 100644 .github/workflows/shellspec.yml diff --git a/.github/workflows/dnsmasq-exec.yml b/.github/workflows/dnsmasq-exec.yml new file mode 100644 index 0000000..a0913a2 --- /dev/null +++ b/.github/workflows/dnsmasq-exec.yml @@ -0,0 +1,22 @@ +--- +name: Update DNS for rui + +on: + workflow_run: + workflows: ["AnsibleLint"] + types: ["completed"] + +jobs: + Dryrun: + runs-on: self-hosted + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: "ansible-play -C --tags dnsmasq rui.yml" + run: | + ansible-playbook \ + -i inventories -C \ + --tags dnsmasq \ + rui.yml 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..a97eed5 --- /dev/null +++ b/.github/workflows/jobs.yml @@ -0,0 +1,63 @@ +--- +name: Hayaworld Ansible Jobs +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: 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" + + Ansible-rui-dns: + needs: + - Yamllint + - AnsibleLint + - Duplicate_Check + 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 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" From d9384d44e7dfb0fbd37fafd99221194adc404e7b Mon Sep 17 00:00:00 2001 From: cradle8810 Date: Fri, 26 Apr 2024 01:32:09 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Rui=E9=96=A2=E9=80=A3=E3=81=AE=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=8C=E5=A4=89=E6=9B=B4=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=ABansible=E3=82=92?= =?UTF-8?q?=E5=9B=9E=E3=81=9B=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dnsmasq-exec.yml | 22 -------------- .github/workflows/jobs.yml | 46 +++++++++++++++++++++++++++++- inventories/host_vars/rui/test.yml | 3 ++ 3 files changed, 48 insertions(+), 23 deletions(-) delete mode 100644 .github/workflows/dnsmasq-exec.yml create mode 100644 inventories/host_vars/rui/test.yml diff --git a/.github/workflows/dnsmasq-exec.yml b/.github/workflows/dnsmasq-exec.yml deleted file mode 100644 index a0913a2..0000000 --- a/.github/workflows/dnsmasq-exec.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Update DNS for rui - -on: - workflow_run: - workflows: ["AnsibleLint"] - types: ["completed"] - -jobs: - Dryrun: - runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: "ansible-play -C --tags dnsmasq rui.yml" - run: | - ansible-playbook \ - -i inventories -C \ - --tags dnsmasq \ - rui.yml diff --git a/.github/workflows/jobs.yml b/.github/workflows/jobs.yml index a97eed5..77f3b81 100644 --- a/.github/workflows/jobs.yml +++ b/.github/workflows/jobs.yml @@ -4,6 +4,7 @@ on: push: branches: - '**' + workflow_dispatch: jobs: Yamllint: @@ -38,11 +39,31 @@ jobs: "./dupcheck.sh" "inventories/host_vars/rui/ads_hosts/NXDOMAIN.yml" - Ansible-rui-dns: + 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 @@ -61,3 +82,26 @@ jobs: --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/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