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
ansible_user: debian
systemd_dir: /etc/systemd/system

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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