diff --git a/ansible/roles/values-prep/tasks/find-node-disks.yml b/ansible/roles/values-prep/tasks/find-node-disks.yml index 9347e55..1c2a637 100644 --- a/ansible/roles/values-prep/tasks/find-node-disks.yml +++ b/ansible/roles/values-prep/tasks/find-node-disks.yml @@ -1,26 +1,31 @@ --- -- name: run lsblk on each nodes - vars: - ip: "{{ lookup('vars', 'node_' ~ item ~ '_ip') }}" - shell: | - ssh core@{{ ip }} \ - "lsblk -J -b -o NAME,TYPE,SIZE,MOUNTPOINT | jq -r ' - .blockdevices[] - | select(.type == \"disk\") - | select(.size > 0) - | select((.children // []) | all(.mountpoint != \"/boot\")) - | \"/dev/\" + .name'" - register: blk_outputs - loop: "{{ range(0,3) | list }}" +- name: Run lsblk on first node + vars: + ip: "{{ lookup('vars', 'node_0_ip') }}" + ansible.builtin.shell: + cmd: >- + ssh core@{{ ip }} "lsblk -J -b -o NAME,TYPE,SIZE,MOUNTPOINT | + jq -r '.blockdevices[] | select(.size > 0 and .type == \"disk\") | + select((.children // []) | all(.mountpoint != \"/boot\")) | \"/dev/\" + .name'" + register: blk_output + changed_when: false -- name: Extract device lists - set_fact: - node_disks_list: "{{ blk_outputs.results | map(attribute='stdout_lines') | list }}" +- name: Get by-path device paths for each disk + vars: + ip: "{{ lookup('vars', 'node_0_ip') }}" + ansible.builtin.shell: + cmd: >- + ssh -o LogLevel=ERROR core@{{ ip }} + 'udevadm info -q symlink -r --name="{{ item }}" | + awk '\''{ for (i = 1; i <= NF; i++) if ($i ~ /disk\/by-path\//) print $i }'\''' + register: by_path_outputs + loop: "{{ blk_output.stdout_lines }}" + changed_when: false -- name: Find common devices accross nodes - set_fact: - common_disks: "{{ node_disks_list[0] | intersect(node_disks_list[1]) | intersect(node_disks_list[2]) }}" +- name: Extract by-path device list + ansible.builtin.set_fact: + common_disks: "{{ by_path_outputs.results | selectattr('stdout', 'defined') | selectattr('stdout', 'ne', '') | map(attribute='stdout') | map('trim') | select('ne', '') | list }}" -- name: common disks - debug: - msg: "{{ common_disks }}" +- name: Display common disks + ansible.builtin.debug: + msg: "{{ common_disks }}" \ No newline at end of file diff --git a/ansible/roles/values-prep/tasks/get_iface.yml b/ansible/roles/values-prep/tasks/get_iface.yml index 86117e0..ed2ae80 100644 --- a/ansible/roles/values-prep/tasks/get_iface.yml +++ b/ansible/roles/values-prep/tasks/get_iface.yml @@ -1,15 +1,15 @@ --- -- name: Get interface for mac {{ item[0] }} - shell: > - ssh core@{{ node_0_ip }} " - ip -o link | - grep -i {{ item[0] }} | - awk -F': ' '{print \$2}' | - grep -v '[.@]' - " +- name: "Get interface for mac {{ item[0] }}" + ansible.builtin.shell: + cmd: >- + ssh core@{{ node_0_ip }} " + ip -o link | + awk -F': ' 'BEGIN{IGNORECASE=1} /{{ item[0] }}/ && \$2 !~ /^br/ {print \$2}' | + grep -v '[.@]' + " register: iface failed_when: iface.rc != 0 and iface.stdout == "" -- name: set iface to fact - set_fact: +- name: Set iface to fact for the current item + ansible.builtin.set_fact: "{{ 'iface_' ~ item[1] }}": "{{ iface.stdout }}" diff --git a/ansible/roles/values-prep/tasks/main.yml b/ansible/roles/values-prep/tasks/main.yml index 4e91e54..bbdc363 100644 --- a/ansible/roles/values-prep/tasks/main.yml +++ b/ansible/roles/values-prep/tasks/main.yml @@ -1,10 +1,11 @@ --- -- name: get woker node names - shell: oc get nodes -o jsonpath='{.items[*].metadata.name}' +- name: Get worker node names + ansible.builtin.command: + cmd: oc get nodes -o jsonpath='{.items[*].metadata.name}' register: node_names -- name: set node facts (node_*) - set_fact: +- name: Set node facts (node_*) + ansible.builtin.set_fact: "{{ item_name }}": "{{ item }}" loop: "{{ node_names.stdout.split() }}" loop_control: @@ -12,70 +13,73 @@ vars: item_name: "node_{{ node_index }}" -- name: get the second node macs (2,3 and 4th macs) - set_fact: +- name: Get the second node MACs (2nd, 3rd and 4th MACs) + ansible.builtin.set_fact: macs: "{{ ocp_inventory.json.nodes[1].mac[1:4] }}" -- name: get the ip of the first node - command: > - oc get nodes -o jsonpath="{range .items[*]}{.status.addresses[?(@.type=='InternalIP')].address}{'\n'}{end}" - register: - nodes_ip +- name: Get the IP of the first node + ansible.builtin.command: + cmd: oc get nodes -o jsonpath="{range .items[*]}{.status.addresses[?(@.type=='InternalIP')].address}{'\n'}{end}" + register: nodes_ip -- name: set node ip fact - set_fact: +- name: Set node IP fact + ansible.builtin.set_fact: "{{ item_name }}": "{{ item }}" loop: "{{ nodes_ip.stdout.split() }}" loop_control: index_var: node_index vars: - item_name: "node_{{ node_index }}_ip" + item_name: "node_{{ node_index }}_ip" -- name: fix and setup ssh - include_tasks: setup-ssh.yml +- name: Fix and setup SSH + ansible.builtin.include_tasks: + file: setup-ssh.yml loop: "{{ range(0, 3) | list }}" -- name: get the interface names - include_tasks: get_iface.yml +- name: Get the interface names + ansible.builtin.include_tasks: + file: get_iface.yml loop: "{{ macs | zip(range(macs | length)) | map('list') | list }}" loop_control: loop_var: item -- name: set the ctlplane gateway ip - shell: - ip addr add 172.16.0.1/16 dev {{ iface_0 }} - become: yes - ignore_errors: yes +- name: Set the ctlplane gateway IP + ansible.builtin.command: + cmd: ip addr add 172.16.0.1/16 dev {{ iface_0 }} + become: true + ignore_errors: true -- name: set masquerade for the jump host - shell: | - iptables -t nat -A POSTROUTING -s 172.16.0.0/16 -o {{ iface_0 }} -j MASQUERADE +- name: Set masquerade for the jump host + ansible.builtin.command: + cmd: iptables -t nat -A POSTROUTING -s 172.16.0.0/16 -o {{ iface_0 }} -j MASQUERADE + become: true -- name: get the common disk accros nodes - include_tasks: find-node-disks.yml +- name: Get the common disk across nodes + ansible.builtin.include_tasks: + file: find-node-disks.yml - name: Render nncp.yaml - template: + ansible.builtin.template: src: nncp_values.yaml.j2 dest: "{{ dt_path }}/examples/dt/perfscale/scalelab/networking/nncp/values.yaml" - name: Render service_values.yaml - template: + ansible.builtin.template: src: service_values.yaml.j2 dest: "{{ dt_path }}/examples/dt/perfscale/scalelab/service-values.yaml" - name: Render service_values_ceph.yaml - template: + ansible.builtin.template: src: service_values_ceph.yaml.j2 dest: "{{ dt_path }}/examples/dt/perfscale/scalelab/service-values-ceph.yaml" when: ceph_backend | default(false) | bool - name: Render kustomization.yaml for controlplane - template: + ansible.builtin.template: src: kustomization.yaml.j2 dest: "{{ dt_path }}/examples/dt/perfscale/scalelab/kustomization.yaml" - name: Render lvms value - template: + ansible.builtin.template: src: lvms-values.yaml.j2 dest: "{{ dt_path }}/examples/dt/perfscale/scalelab/lvms/lvm-cluster/values.yaml" diff --git a/ansible/roles/values-prep/tasks/setup-ssh.yml b/ansible/roles/values-prep/tasks/setup-ssh.yml index 89a78e9..56ee383 100644 --- a/ansible/roles/values-prep/tasks/setup-ssh.yml +++ b/ansible/roles/values-prep/tasks/setup-ssh.yml @@ -1,9 +1,10 @@ --- -- name: remove bad known_host entry if any - shell: - ssh-keygen -R {{ lookup('vars', 'node_' ~ item ~ '_ip') }} - ignore_errors: yes +- name: Remove bad known_host entry if any + ansible.builtin.command: + cmd: ssh-keygen -R {{ lookup('vars', 'node_' ~ item ~ '_ip') }} + ignore_errors: true - name: Add node to known hosts - shell: ssh-keyscan -H {{ lookup('vars', 'node_' ~ item ~ '_ip') }} >> ~/.ssh/known_hosts - ignore_errors: yes + ansible.builtin.shell: + cmd: ssh-keyscan -H {{ lookup('vars', 'node_' ~ item ~ '_ip') }} >> ~/.ssh/known_hosts + ignore_errors: true