Skip to content

Commit

Permalink
Fixes k3s-io#3: Fix linting issues, add ansible-lint and yamllint con…
Browse files Browse the repository at this point in the history
…figuration.
  • Loading branch information
geerlingguy committed May 12, 2020
1 parent bad25d1 commit e47af78
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 46 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
extends: default

rules:
line-length:
max: 120
level: warning
truthy:
allowed-values: ['true', 'false', 'yes', 'no']
1 change: 1 addition & 0 deletions inventory/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
k3s_version: v0.8.1
ansible_user: debian
systemd_dir: /etc/systemd/system
Expand Down
2 changes: 1 addition & 1 deletion reset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
gather_facts: yes
become: yes
roles:
- { role: reset }
- role: reset
45 changes: 22 additions & 23 deletions roles/download/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 8 additions & 6 deletions roles/k3s/master/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions roles/prereq/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
14 changes: 7 additions & 7 deletions roles/raspbian/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
12 changes: 5 additions & 7 deletions site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e47af78

Please sign in to comment.