|
| 1 | +--- |
| 2 | +# Copyright Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +- name: Set custom cifmw PATH reusable fact |
| 18 | + tags: |
| 19 | + - always |
| 20 | + when: |
| 21 | + - cifmw_path is not defined |
| 22 | + ansible.builtin.set_fact: |
| 23 | + cifmw_path: "{{ ansible_user_dir }}/.crc/bin:{{ ansible_user_dir }}/.crc/bin/oc:{{ ansible_user_dir }}/bin:{{ ansible_env.PATH }}" |
| 24 | + cacheable: true |
| 25 | + |
| 26 | +- name: Install required packages |
| 27 | + ansible.builtin.package: |
| 28 | + name: |
| 29 | + - nfs-utils |
| 30 | + - iptables |
| 31 | + |
| 32 | +- name: Configure nfs to use v4 only |
| 33 | + community.general.ini_file: |
| 34 | + path: /etc/nfs.conf |
| 35 | + section: nfsd |
| 36 | + option: vers3 |
| 37 | + value: n |
| 38 | + backup: true |
| 39 | + mode: "0644" |
| 40 | + |
| 41 | +- name: Disable NFSv3-related services |
| 42 | + ansible.builtin.systemd_service: |
| 43 | + name: "{{ item }}" |
| 44 | + masked: true |
| 45 | + loop: |
| 46 | + - rpc-statd.service |
| 47 | + - rpcbind.service |
| 48 | + - rpcbind.socket |
| 49 | + |
| 50 | +- name: Ensure shared folder exist |
| 51 | + ansible.builtin.file: |
| 52 | + path: "/data/{{ item }}" |
| 53 | + state: directory |
| 54 | + mode: '755' |
| 55 | + loop: "{{ cifmw_nfs_shares }}" |
| 56 | + |
| 57 | +- name: Set nfs network vars |
| 58 | + delegate_to: controller |
| 59 | + environment: |
| 60 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 61 | + PATH: "{{ cifmw_path }}" |
| 62 | + vars: |
| 63 | + _nfs_network_name: "{{ cifmw_nfs_network }}" |
| 64 | + _nfs_host: "{{ [groups[cifmw_nfs_target][0], ansible_domain] | select() | join('.') | default('') }}" |
| 65 | + _ipset_namespace: "{{ cifmw_install_yamls_defaults['NAMESPACE'] | default('openstack') }}" |
| 66 | + ansible.builtin.command: |
| 67 | + cmd: oc get ipset {{ _nfs_host }} -n {{ _ipset_namespace }} -o jsonpath='{.status.reservations[?(@.network=="{{ _nfs_network_name }}")]}' |
| 68 | + register: cifmw_nfs_network_out |
| 69 | + |
| 70 | +- name: Store nfs network vars |
| 71 | + delegate_to: controller |
| 72 | + ansible.builtin.copy: |
| 73 | + dest: "{{ cifmw_basedir }}/artifacts/parameters/nfs-params.yml" |
| 74 | + content: >- |
| 75 | + {{ |
| 76 | + { |
| 77 | + 'cifmw_nfs_ip': cifmw_nfs_network_out.stdout | from_json | json_query('address'), |
| 78 | + 'cifmw_nfs_network_range': cifmw_nfs_network_out.stdout | from_json | json_query('cidr') |
| 79 | + } | to_nice_yaml |
| 80 | + }} |
| 81 | + mode: "0644" |
| 82 | + |
| 83 | +# NOTE: This represents a workaround because there's an edpm-nftables role |
| 84 | +# in edpm-ansible already. That role should contain the implementation |
| 85 | +# of the firewall rules for NFS, and they should be included in the |
| 86 | +# main edpm-rules.nft file. The following firewall config assumes that |
| 87 | +# the EDPM node has been configured in terms of networks and firewall. |
| 88 | +- name: Configure firewall |
| 89 | + become: true |
| 90 | + tags: |
| 91 | + - nft |
| 92 | + block: |
| 93 | + - name: Generate nftables rules file |
| 94 | + ansible.builtin.copy: |
| 95 | + content: | |
| 96 | + add rule inet filter EDPM_INPUT tcp dport 2049 accept |
| 97 | + dest: "{{ nftables_path }}/nfs-server.nft" |
| 98 | + mode: '0666' |
| 99 | + |
| 100 | + - name: Update nftables.conf and include nfs rules at the bottom |
| 101 | + ansible.builtin.lineinfile: |
| 102 | + path: "{{ nftables_conf }}" |
| 103 | + line: include "{{ nftables_path }}/nfs-server.nft" |
| 104 | + insertafter: EOF |
| 105 | + |
| 106 | + - name: Restart nftables service |
| 107 | + ansible.builtin.systemd: |
| 108 | + name: nftables |
| 109 | + state: restarted |
| 110 | + |
| 111 | +- name: Configure the ip the nfs server should listen on |
| 112 | + community.general.ini_file: |
| 113 | + path: /etc/nfs.conf |
| 114 | + section: nfsd |
| 115 | + option: host |
| 116 | + value: "{{ cifmw_nfs_network_out.stdout | from_json | json_query('address') }}" |
| 117 | + backup: true |
| 118 | + mode: "0644" |
| 119 | + |
| 120 | +- name: Enable and restart nfs-server service |
| 121 | + ansible.builtin.systemd: |
| 122 | + name: nfs-server |
| 123 | + state: restarted |
| 124 | + enabled: true |
| 125 | + |
| 126 | +- name: Add shares to /etc/exports |
| 127 | + ansible.builtin.lineinfile: |
| 128 | + path: /etc/exports |
| 129 | + line: "/data/{{ item }} {{ cifmw_nfs_network_out.stdout | from_json | json_query('cidr') }}(rw,sync,no_root_squash)" |
| 130 | + loop: "{{ cifmw_nfs_shares }}" |
| 131 | + register: _export_shares |
| 132 | + |
| 133 | +- name: Export the shares # noqa: no-handler |
| 134 | + when: |
| 135 | + - _export_shares.changed |
| 136 | + ansible.builtin.command: exportfs -a |
0 commit comments