Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wenerme committed Jul 10, 2023
1 parent 1e1df23 commit 2d074e2
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 35 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ publish: build
ansible-galaxy collection publish wenerme-alpine-$(shell yq r galaxy.yml version).tar.gz --api-key $$API_KEY

lint:
docker run --rm -h toolset -v $(PWD):/host -w /host quay.io/ansible/toolset ansible-lint
docker run --rm -h toolset -v $(PWD):/host -w /host quay.io/ansible/creator-ee ansible-lint

dev:
@#docker run --rm -h toolset --entrypoint bash -it -v $(PWD):/host -w /host registry.cn-hongkong.aliyuncs.com/cmi/ansible_creator-ee
docker run --rm -h toolset --entrypoint bash -it -v $(PWD):/host -w /host quay.io/ansible/toolset

ci: lint
3 changes: 2 additions & 1 deletion playbooks/inv-keygen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
file:
path: "{{inv_name}}/credentials"
state: directory
mode: 0600
# ssh-keygen -t rsa -b 2048 -f ${inv_name}/credentials/admin_rsa -C "$inv_name-admin" -q -N ""
- openssh_keypair:
- community.crypto.openssh_keypair:
path: "{{inv_name}}/credentials/admin_rsa"
size: 2048
comment: Administrator
Expand Down
2 changes: 1 addition & 1 deletion playbooks/inv-ssh-copy-id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
when: remote_user is undefined
- name: Set authorized key taken from file
become: "{{remote_user != ansible_user}}"
authorized_key:
community.crypto.authorized_key:
user: "{{remote_user}}"
state: present
key: "{{ lookup('file', inv_name+'/credentials/admin_rsa.pub') }}"
2 changes: 1 addition & 1 deletion playbooks/ssh-copy-id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
tasks:
- name: Set authorized key taken from file
become: "{{ remote_user != ansible_user }}"
authorized_key:
community.crypto.authorized_key:
user: "{{ remote_user }}"
state: present
key: "{{ lookup('file', ssh_pub_key_file) }}"
8 changes: 5 additions & 3 deletions roles/alpine/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# alpine mirror
# https://mirrors.ustc.edu.cn/alpine - slower
# alpine_mirror: https://mirrors.aliyun.com/alpine
alpine_mirror: https://mirrors.sjtug.sjtu.edu.cn/alpine
# https://mirrors.ustc.edu.cn/alpine - 上海访问慢
# https://mirrors.aliyun.com/alpine - 可能慢几天
# https://mirrors.sjtug.sjtu.edu.cn/alpine - 没那么稳定
# https://mirrors.tuna.tsinghua.edu.cn/alpine
alpine_mirror: https://mirrors.tuna.tsinghua.edu.cn/alpine

# docker mirror
docker_mirror: https://docker.mirrors.ustc.edu.cn
Expand Down
6 changes: 3 additions & 3 deletions roles/alpine/tasks/hostname.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# - "{{hostname|default('n/a')}}"
# - "{{inventory_hostname}}"

- name: set hostname
- name: set hostname to "{{ hostname|default(inventory_hostname) }}"
become: true
hostname:
ansible.builtin.hostname:
name: "{{ hostname|default(inventory_hostname) }}"
use: alpine

Expand All @@ -18,4 +18,4 @@
state: present
loop:
- "127.0.0.1"
- "::"
- "::1"
14 changes: 14 additions & 0 deletions roles/alpine/tasks/k0s-logrotate-conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- name: k0s logrotate
become: true
copy:
dest: /etc/logrotate.d/k0s
mode: 0644
content: |
/var/log/k0s.log {
missingok
notifempty
copytruncate
daily
rotate 7
maxage 365
}
21 changes: 12 additions & 9 deletions roles/alpine/tasks/k3s-install.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# crond
# apk add coreutils findutils iptables iproute2 nfs-utils
- name: k3s | install deps
become: true
package:
name: "{{ item }}"
state: present
loop:
- conntrack-tools
- containerd
- coreutils
- dbus
- findutils
- ipset
- iptables
- musl
- socat
- iproute2
- nfs-utils
- cni-plugins
- k3s
- k3s-openrc

# - conntrack-tools
# - containerd
# - dbus
# - ipset
# - socat
# - cni-plugins
# - k3s
# - k3s-openrc
# apk add coreutils findutils iptables musl iproute2 nfs-utils socat
# apk add conntrack-tools coreutils dbus findutils ipvsadm ipset iptables socat iproute2 nfs-utils
# sudo apk del k3s cni-plugins conntrack-tools containerd dbus ipset socat

# < v3.13
# - name: k3s | install cni-plugins
Expand Down
2 changes: 1 addition & 1 deletion roles/alpine/tasks/local-service.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: enable local server
- name: local service | enable
become: true
service:
name: local
Expand Down
6 changes: 6 additions & 0 deletions roles/alpine/tasks/logrotate-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: logrotate | install
become: true
apk:
name: logrotate

- import_tasks: crond-service.yaml
1 change: 1 addition & 0 deletions roles/alpine/tasks/ntp-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
when: ntp_service is undefined

- name: ntp-service | install chrony
become: true
apk:
name: chrony
when: ntp_service == 'chronyd'
Expand Down
3 changes: 3 additions & 0 deletions roles/alpine/tasks/setup-ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- tree
- rsync
- htop
- btop
- procps
- lsof
# 网络
- iftop
- tcpdump
Expand Down
8 changes: 5 additions & 3 deletions roles/alpine/tasks/setup-phy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- bind-tools
- tcpdump
- dmidecode
# - lm-sernsor
# - lm-sensors-sensord
# - lm-sensors-detect
# server hw
- lm-sensors
- lm-sensors-sensord
- lm-sensors-detect
- smartmontools
14 changes: 8 additions & 6 deletions roles/alpine/tasks/tinc-install.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
- name: tinc | install tinc-pre
become: true
apk:
name: tinc-pre

- name: tinc | load modules
become: true
modprobe:
Expand All @@ -17,5 +12,12 @@
path: /etc/modules-load.d/tinc.conf
line: "{{ item }}"
create: true
mode: 0644
loop: *modules

- name: tinc | install
become: true
package:
name: "{{ item }}"
state: present
loop:
- tinc-pre
12 changes: 6 additions & 6 deletions roles/alpine/tasks/tinc-supervise-install.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- name: tinc | install tincd.netanme service
- name: tinc | install tinc.netanme service
become: true
copy:
dest: /etc/init.d/tincd.netname
dest: /etc/init.d/tinc.netname
mode: +x
content: |
#!/sbin/openrc-run
Expand Down Expand Up @@ -34,7 +34,7 @@
checkconfig() {
# warn this if not found
if [ ! -f "/etc/tinc/$NETNAME/tinc.conf" ] ; then
if [ ! -f "/etc/tinc/$NETNAME/tinc.conf" ]; then
eerror "No VPN network configured"
return 1
fi
Expand All @@ -47,10 +47,10 @@
eend $?
}
- name: tinc | install tincd.{{ tinc_netname }}
- name: tinc | install tinc.{{ tinc_netname }}
become: true
file:
dest: /etc/init.d/tincd.{{ tinc_netname }}
src: /etc/init.d/tincd.netname
dest: /etc/init.d/tinc.{{ tinc_netname }}
src: /etc/init.d/tinc.netname
state: link
when: tinc_netname is defined
54 changes: 54 additions & 0 deletions roles/alpine/tasks/zfs-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
- name: zfs-service | ensure udev
include_tasks: ensure-service.yaml
vars:
- service_name: udev

- setup:
when: ansible_kernel is undefined
name: zfs-service | gather

- name: zfs-service | install zfs with kernal {{ ansible_kernel }}
become: true
apk:
name: "{{ item }}"
loop:
- zfs
- zfs-udev
- "zfs-{{ ansible_kernel | regex_search('-([a-z]*?)$','\\1') | first | default('lts') }}"

- name: zfs-service | load zfs module
become: true
modprobe:
name: zfs
state: present

- name: zfs-service | persist zfs mpdule
become: true
lineinfile:
path: /etc/modules-load.d/zfs.conf
line: zfs
create: true
mode: 0644

- name: zfs-service | start zfs
become: true
service:
name: "{{ item }}"
state: started
loop:
- zfs-import
- zfs-mount
tags:
- service-start

- name: zfs-service | enable zfs on boot
become: true
service:
name: "{{ item }}"
enabled: true
runlevel: sysinit
loop:
- zfs-import
- zfs-mount
tags:
- service-enable

0 comments on commit 2d074e2

Please sign in to comment.