Skip to content

Commit

Permalink
[devsetup] allow configure nfs server on host
Browse files Browse the repository at this point in the history
Related: OSPRH-6624

Signed-off-by: Martin Schuppert <[email protected]>
  • Loading branch information
stuggi committed Aug 14, 2024
1 parent 47acf39 commit 427efde
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ warn_list:
exclude_paths:
- devsetup/standalone/network_data.yaml
- devsetup/standalone/deployed_network.yaml
skip_list:
- no-handler
18 changes: 18 additions & 0 deletions devsetup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ IPV6_LAB_SNO_OCP_MIRROR_URL ?= https://mirror.openshift.com/pub/openshift-
# default number of instances to deploy via edpm_deploy_instance
NUMBER_OF_INSTANCES ?=1

# base directory used for the nfs server
NFS_HOME ?= /home/nfs

STANDALONE_COMPUTE_DRIVER ?= libvirt

CLEANUP_DIR_CMD ?= rm -Rf

define vars
${1}: export CLEANUP_DIR_CMD=${CLEANUP_DIR_CMD}
${1}: export NFS_HOME=${NFS_HOME}
endef

##@ General
Expand All @@ -168,6 +172,20 @@ download_tools: ## Runs an ansible playbook to install required tools with the v
-v -i hosts --tags ${DOWNLOAD_TOOLS_SELECTION} \
download_tools.yaml

##@ Configure nfs server on the host
.PHONY: nfs
nfs: ## Runs an ansible playbook to install nfs rpms, uses per default /home/nfs as the data dir and exports shared for OSP services.
$(eval $(call vars))
ANSIBLE_FORCE_COLOR=true ansible-playbook \
-v -i hosts nfs.yaml

.PHONY: nfs_cleanup
nfs_cleanup: ## removes /etc/exports.d/osp.exports, reloads nfs exports and deletes /home/nfs
$(eval $(call vars))
sudo rm -f /etc/exports.d/osp.exports
sudo exportfs -ra
sudo ${CLEANUP_DIR_CMD} ${NFS_HOME}

##@ CRC
.PHONY: crc
crc: ## Deploys CRC using CRC_URL to download and install CRC, KUBEADMIN_PWD as the password which defaults to 12345678 and PULL_SECRET to specify the file containing the pull secret, defaults to ${PWD}/pull-secret.txt. To change the default memory and/or cpus for the VM use `CPUS=X MEMORY=Y DISK=Z make crc`.
Expand Down
10 changes: 10 additions & 0 deletions devsetup/nfs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ansible-playbook
---
- name: Configure nfs server and exports
become: true
hosts: localhost
gather_facts: true
roles:
- role: nfs_server
vars:
nfs_home: "{{ lookup('ansible.builtin.env', 'NFS_HOME')|default('/home/nfs', True) }}"
2 changes: 2 additions & 0 deletions devsetup/roles/nfs_server/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
nfs_home: /home/nfs
54 changes: 54 additions & 0 deletions devsetup/roles/nfs_server/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- name: Install NFS packages
ansible.builtin.yum:
name: nfs-utils
state: present

- name: Start and enable NFS services
ansible.builtin.systemd:
name: nfs-server
state: started
enabled: true

- name: Open nfsv4 port 2049/tcp (running config, non permanent)
ansible.builtin.iptables:
chain: INPUT
destination_port: 2049
protocol: tcp
ctstate: NEW
syn: match
jump: ACCEPT
comment: Accept new NFS connections.

- name: Create NFS shares
ansible.builtin.file:
path: "{{ nfs_home }}/{{ item }}"
state: directory
mode: '0777'
group: nobody
owner: nobody
with_items:
- glance
- glance-staging
- nova
- cinder
- cinder_image_conversion

- name: Configure exports
ansible.builtin.lineinfile:
path: /etc/exports.d/osp.exports
line: "{{ nfs_home }}/{{ item }} *(rw,sync,no_root_squash)"
create: true
mode: '0644'
with_items:
- glance
- glance-staging
- nova
- cinder
- cinder_image_conversion
register: _export_shares

- name: Export NFS share to the server
when:
- _export_shares.changed
ansible.builtin.command: "exportfs -r"

0 comments on commit 427efde

Please sign in to comment.