Fixes #3: Fix linting issues, add ansible-lint and yamllint configuration.

This commit is contained in:
Jeff Geerling 2020-05-12 15:17:06 -05:00
parent bad25d1ba5
commit e47af78bfd
9 changed files with 86 additions and 46 deletions

31
.github/workflows/lint.yml vendored Normal file
View File

@ -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

9
.yamllint Normal file
View File

@ -0,0 +1,9 @@
---
extends: default
rules:
line-length:
max: 120
level: warning
truthy:
allowed-values: ['true', 'false', 'yes', 'no']

View File

@ -1,3 +1,4 @@
---
k3s_version: v0.8.1 k3s_version: v0.8.1
ansible_user: debian ansible_user: debian
systemd_dir: /etc/systemd/system systemd_dir: /etc/systemd/system

View File

@ -4,4 +4,4 @@
gather_facts: yes gather_facts: yes
become: yes become: yes
roles: roles:
- { role: reset } - role: reset

View File

@ -7,32 +7,31 @@
- name: Download k3s binary x64 - name: Download k3s binary x64
get_url: get_url:
url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s
dest: /usr/local/bin/k3s dest: /usr/local/bin/k3s
owner: root owner: root
group: root group: root
mode: 755 mode: 755
# when: ( ansible_facts.userspace_architecture == "x86_64" ) when: ansible_facts.architecture == "x86_64"
when: ( ansible_facts.architecture == "x86_64" )
- name: Download k3s binary arm64 - name: Download k3s binary arm64
get_url: get_url:
url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-arm64 url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-arm64
dest: /usr/local/bin/k3s dest: /usr/local/bin/k3s
owner: root owner: root
group: root group: root
mode: 755 mode: 755
when: ( ansible_facts.architecture is search("arm") ) when:
and - ansible_facts.architecture is search("arm")
( ansible_facts.userspace_bits == "64" ) - ansible_facts.userspace_bits == "64"
- name: Download k3s binary armhf - name: Download k3s binary armhf
get_url: get_url:
url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-armhf url: https://github.com/rancher/k3s/releases/download/{{ k3s_version }}/k3s-armhf
dest: /usr/local/bin/k3s dest: /usr/local/bin/k3s
owner: root owner: root
group: root group: root
mode: 755 mode: 755
when: ( ansible_facts.architecture is search("arm") ) when:
and - ansible_facts.architecture is search("arm")
( ansible_facts.userspace_bits == "32" ) - ansible_facts.userspace_bits == "32"

View File

@ -36,10 +36,10 @@
register: node_token register: node_token
- name: Store Master node-token - name: Store Master node-token
set_fact: set_fact:
token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}" token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}"
- name: Restore node-token file access - name: Restore node-token file access
file: file:
path: /var/lib/rancher/k3s/server path: /var/lib/rancher/k3s/server
mode: "{{ p.stat.mode }}" mode: "{{ p.stat.mode }}"
@ -58,9 +58,11 @@
owner: "{{ ansible_user }}" owner: "{{ ansible_user }}"
- name: Replace https://localhost:6443 by https://master-pi:6443 - name: Replace https://localhost:6443 by https://master-pi:6443
command: k3s kubectl config set-cluster default command: >-
--server=https://{{ master_ip }}:6443 k3s kubectl config set-cluster default
--kubeconfig ~{{ ansible_user }}/.kube/config --server=https://{{ master_ip }}:6443
--kubeconfig ~{{ ansible_user }}/.kube/config
changed_when: true
- name: Create kubectl symlink - name: Create kubectl symlink
file: file:

View File

@ -2,7 +2,7 @@
- name: Set SELinux to disabled state - name: Set SELinux to disabled state
selinux: selinux:
state: disabled 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 - name: Enable IPv4 forwarding
sysctl: sysctl:
@ -24,7 +24,7 @@
value: "1" value: "1"
state: present state: present
reload: yes reload: yes
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']
loop: loop:
- net.bridge.bridge-nf-call-iptables - net.bridge.bridge-nf-call-iptables
- net.bridge.bridge-nf-call-ip6tables - net.bridge.bridge-nf-call-ip6tables

View File

@ -11,13 +11,13 @@
regexp: '^(.*rootwait)$' regexp: '^(.*rootwait)$'
line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
backrefs: true backrefs: true
when: ( cmdline.stat.path is defined ) when:
and - cmdline.stat.path is defined
( ansible_facts.architecture is search("arm") ) - ansible_facts.architecture is search("arm")
register: boot_cmdline register: boot_cmdline
- name: Rebooting on Raspbian - name: Rebooting on Raspbian
reboot: reboot:
when: ( boot_cmdline is changed ) when:
and - boot_cmdline | changed
( ansible_facts.architecture is search("arm") ) - ansible_facts.architecture is search("arm")

View File

@ -4,19 +4,17 @@
gather_facts: yes gather_facts: yes
become: yes become: yes
roles: roles:
- { role: prereq } - role: prereq
- { role: download } - role: download
- { role: raspbian } - role: raspbian
- hosts: master - hosts: master
# gather_facts: yes
become: yes become: yes
roles: roles:
- { role: k3s/master } - role: k3s/master
- hosts: node - hosts: node
# gather_facts: yes
become: yes become: yes
roles: roles:
- { role: k3s/node } - role: k3s/node