Skip to content

Commit

Permalink
working tftp server
Browse files Browse the repository at this point in the history
  • Loading branch information
estenrye committed Sep 29, 2022
1 parent 75be048 commit 271998e
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ansible/playbooks/tools.rye.ninja/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ docker run --rm -it \
--mount type=bind,source=${ANSIBLE_SECRETS_DIR},target=/secrets \
--mount type=bind,source=${SSH_KEY_PATH},target=/root/.ssh/id_rsa \
-e ANSIBLE_CONFIG=/ansible/ansible.cfg \
estenrye/ansible:latest \
estenrye/ansible:v0.2.9 \
ansible-playbook \
-i /ansible/playbooks/tools.rye.ninja/inventory.yml \
/ansible/playbooks/tools.rye.ninja/playbook.yml
Expand Down
69 changes: 69 additions & 0 deletions ansible/playbooks/tools.rye.ninja/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,74 @@
update_cache: yes
cache_valid_time: 3600
become: true

- name: task for creating volume group
community.general.lvg:
vg: data-vg
pvs: /dev/sdb
pesize: 16
become: true

- name: Install lvm2 dependency
ansible.builtin.package:
name: lvm2
state: present
become: true

- name: task for creating logical volume
community.general.lvol:
vg: data-vg
lv: "{{ lv_item.lv }}"
size: "{{ lv_item.size }}"
loop_control:
loop_var: lv_item
loop:
- lv: apt-lv
size: 1024g
- lv: pxe-lv
size: 500g
become: true

- name: Create directory data1 if does not exist
ansible.builtin.file:
path: "{{ lv_path }}"
state: directory
mode: '0755'
loop_control:
loop_var: lv_path
loop:
- /var/lib/apt-mirror
- /var/lib/pxeroot
become: true

- name: format the xfs filesystem
ansible.builtin.filesystem:
fstype: xfs
dev: "{{ lv_dev }}"
loop_control:
loop_var: lv_dev
loop:
- /dev/data-vg/apt-lv
- /dev/data-vg/pxe-lv
become: true

- name: mount the lv on /data1
ansible.builtin.mount:
path: "{{ lv_mount.path }}"
src: "{{ lv_mount.src }}"
fstype: xfs
state: mounted
loop_control:
loop_var: lv_mount
loop:
- path: /var/lib/apt-mirror
src: /dev/data-vg/apt-lv
- path: /var/lib/pxeroot
src: /dev/data-vg/pxe-lv
become: true

- hosts: tools_server
roles:
- keepalived
- shoelaces
- tftp
12 changes: 12 additions & 0 deletions ansible/roles/shoelaces/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
shoelaces_version: 1.2.0
shoelaces_repo_url: https://github.com/estenrye/shoelaces
shoelaces_system: "{{ ansible_system | lower }}"
shoelaces_arch: "{% if ansible_architecture == 'x86_64' %}amd64{% else %}arm64{% endif %}"
shoelaces_release_url: "{{ shoelaces_repo_url }}/releases/download/v{{ shoelaces_version }}/shoelaces_{{ shoelaces_version }}_{{ shoelaces_system }}_{{ shoelaces_arch }}.tar.gz"

shoelaces_bind_addr: localhost:8081
shoelaces_data_dir: configs/data-dir
shoelaces_domain: localhost
shoelaces_template_extenstion: .slc
shoelaces_mappings_file: mappings.yaml
shoelaces_debug: true
16 changes: 16 additions & 0 deletions ansible/roles/shoelaces/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Download Shoelaces Artifact
ansible.builtin.get_url:
url: "{{ shoelaces_release_url }}"
dest: /tmp/shoelaces.tar.gz

- name: Unarchive Shoelaces Artifact
ansible.builtin.unarchive:
src: /tmp/shoelaces.tar.gz
remote_src: true
dest: /usr/bin
mode: 755
owner: root
group: root
include:
- shoelaces
become: true
6 changes: 6 additions & 0 deletions ansible/roles/shoelaces/templates/shoelaces.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bind-addr={{ shoelaces_bind_addr }}
data-dir={{ shoelaces_data_dir }}
domain={{ shoelaces_domain }}
template-extension={{ shoelaces_template_extension }}
mappings-file={{ shoelaces_mappings_file }}
debug={{ shoelaces_debug | boolean | lower }}
8 changes: 8 additions & 0 deletions ansible/roles/tftp/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tftp_user: tftp
tftp_uid: 35000
tftp_group: tftp
tftp_gid: 35000
tftp_directory: /var/lib/pxeroot
tftp_address: :69
tftp_options:
- --secure
6 changes: 6 additions & 0 deletions ansible/roles/tftp/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: restart tftpd-hpa
service:
name: tftpd-hpa
state: restarted
become: true
47 changes: 47 additions & 0 deletions ansible/roles/tftp/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
- name: Create tftp Group if it does not exist
ansible.builtin.group:
gid: "{{ tftp_gid | int }}"
name: "{{ tftp_group }}"
become: true

- name: Create tftp User if it does not exist
ansible.builtin.user:
uid: "{{ tftp_uid | int }}"
name: "{{ tftp_user }}"
group: "{{ tftp_group }}"
become: true

- name: set ownership of tftp_directory
ansible.builtin.file:
state: directory
path: "{{ tftp_directory }}"
owner: "{{ tftp_user }}"
group: "{{ tftp_group }}"
become: true

- name: Install tftp-hpa package
ansible.builtin.package:
name:
- tftp-hpa
- tftpd-hpa

become: true

- name: Create Configuration Files
ansible.builtin.template:
src: tftpd-hpa.conf.j2
dest: /etc/default/tftpd-hpa
notify: restart tftpd-hpa
become: true

- name: Ensure keepalived is enabled on boot.
ansible.builtin.service:
name: tftpd-hpa
enabled: yes
become: true

- name: Ensure keepalived is started.
ansible.builtin.service:
name: tftpd-hpa
state: started
become: true
6 changes: 6 additions & 0 deletions ansible/roles/tftp/templates/tftpd-hpa.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# {{ ansible_managed }}

TFTP_USERNAME="{{ tftp_user }}"
TFTP_DIRECTORY="{{ tftp_directory }}"
TFTP_ADDRESS="{{ tftp_address }}"
TFTP_OPTIONS="{{ tftp_options | join(' ') }}"

0 comments on commit 271998e

Please sign in to comment.