diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..991b2c6 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,31 @@ +--- +name: Lint +'on': + pull_request: + push: + branches: + - master + +jobs: + + test: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + + - name: Set up Python 3.7. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install yamllint ansible-lint + + - name: Run yamllint. + run: yamllint . + + - name: Run ansible-lint. + run: ansible-lint diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..8f19687 --- /dev/null +++ b/.yamllint @@ -0,0 +1,9 @@ +--- +extends: default + +rules: + line-length: + max: 120 + level: warning + truthy: + allowed-values: ['true', 'false', 'yes', 'no'] diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml index d80065e..da6ae19 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -1,3 +1,4 @@ +--- k3s_version: v0.8.1 ansible_user: debian systemd_dir: /etc/systemd/system diff --git a/reset.yml b/reset.yml index 435de02..77577fd 100644 --- a/reset.yml +++ b/reset.yml @@ -4,4 +4,4 @@ gather_facts: yes become: yes roles: - - { role: reset } + - role: reset diff --git a/roles/download/tasks/main.yml b/roles/download/tasks/main.yml index bdcb2ba..961a4c4 100644 --- a/roles/download/tasks/main.yml +++ b/roles/download/tasks/main.yml @@ -7,32 +7,31 @@ - name: Download k3s binary x64 get_url: - url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s - dest: /usr/local/bin/k3s - owner: root - group: root - mode: 755 -# when: ( ansible_facts.userspace_architecture == "x86_64" ) - when: ( ansible_facts.architecture == "x86_64" ) + url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s + dest: /usr/local/bin/k3s + owner: root + group: root + mode: 755 + when: ansible_facts.architecture == "x86_64" - name: Download k3s binary arm64 get_url: - url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-arm64 - dest: /usr/local/bin/k3s - owner: root - group: root - mode: 755 - when: ( ansible_facts.architecture is search("arm") ) - and - ( ansible_facts.userspace_bits == "64" ) + url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-arm64 + dest: /usr/local/bin/k3s + owner: root + group: root + mode: 755 + when: + - ansible_facts.architecture is search("arm") + - ansible_facts.userspace_bits == "64" - name: Download k3s binary armhf get_url: - url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-armhf - dest: /usr/local/bin/k3s - owner: root - group: root - mode: 755 - when: ( ansible_facts.architecture is search("arm") ) - and - ( ansible_facts.userspace_bits == "32" ) + url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-armhf + dest: /usr/local/bin/k3s + owner: root + group: root + mode: 755 + when: + - ansible_facts.architecture is search("arm") + - ansible_facts.userspace_bits == "32" diff --git a/roles/k3s/master/tasks/main.yml b/roles/k3s/master/tasks/main.yml index f2e05c1..b889c10 100644 --- a/roles/k3s/master/tasks/main.yml +++ b/roles/k3s/master/tasks/main.yml @@ -36,10 +36,10 @@ register: node_token - name: Store Master node-token - set_fact: - token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}" + set_fact: + token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}" -- name: Restore node-token file access +- name: Restore node-token file access file: path: /var/lib/rancher/k3s/server mode: "{{ p.stat.mode }}" @@ -58,9 +58,11 @@ owner: "{{ ansible_user }}" - name: Replace https://localhost:6443 by https://master-pi:6443 - command: k3s kubectl config set-cluster default - --server=https://{{ master_ip }}:6443 - --kubeconfig ~{{ ansible_user }}/.kube/config + command: >- + k3s kubectl config set-cluster default + --server=https://{{ master_ip }}:6443 + --kubeconfig ~{{ ansible_user }}/.kube/config + changed_when: true - name: Create kubectl symlink file: diff --git a/roles/prereq/tasks/main.yml b/roles/prereq/tasks/main.yml index 738513c..8c6685c 100644 --- a/roles/prereq/tasks/main.yml +++ b/roles/prereq/tasks/main.yml @@ -2,7 +2,7 @@ - name: Set SELinux to disabled state selinux: state: disabled - when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' + when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux'] - name: Enable IPv4 forwarding sysctl: @@ -24,7 +24,7 @@ value: "1" state: present reload: yes - when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' + when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux'] loop: - net.bridge.bridge-nf-call-iptables - net.bridge.bridge-nf-call-ip6tables diff --git a/roles/raspbian/tasks/main.yml b/roles/raspbian/tasks/main.yml index 370d2c6..0d92d70 100644 --- a/roles/raspbian/tasks/main.yml +++ b/roles/raspbian/tasks/main.yml @@ -11,13 +11,13 @@ regexp: '^(.*rootwait)$' line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' backrefs: true - when: ( cmdline.stat.path is defined ) - and - ( ansible_facts.architecture is search("arm") ) + when: + - cmdline.stat.path is defined + - ansible_facts.architecture is search("arm") register: boot_cmdline -- name: Rebooting on Raspbian +- name: Rebooting on Raspbian reboot: - when: ( boot_cmdline is changed ) - and - ( ansible_facts.architecture is search("arm") ) + when: + - boot_cmdline | changed + - ansible_facts.architecture is search("arm") diff --git a/site.yml b/site.yml index 9c5a2eb..f7fa9ac 100644 --- a/site.yml +++ b/site.yml @@ -4,19 +4,17 @@ gather_facts: yes become: yes roles: - - { role: prereq } - - { role: download } - - { role: raspbian } + - role: prereq + - role: download + - role: raspbian - hosts: master -# gather_facts: yes become: yes roles: - - { role: k3s/master } + - role: k3s/master - hosts: node -# gather_facts: yes become: yes roles: - - { role: k3s/node } + - role: k3s/node