Step: baremetalds-packet-setup

This step performs the setup of the packet server

Container image used for this step: dev-scripts

dev-scripts resolves to an image built or imported by the ci-operator configuration (documentation).

Environment

In addition to the default environment, the step exposes the following:

Variable Name Type Variable Content
PACKET_PLAN Parameter[?] Plan to use in Packet when creating a testing machine. (default: m2.xlarge.x86)

Source Code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash

set -o nounset
set -o errexit
set -o pipefail

echo "************ baremetalds packet setup command ************"

# Run Ansible playbook
cd
cat > packet-setup.yaml <<-EOF
- name: setup Packet host
  hosts: localhost
  collections:
   - community.general
  gather_facts: no
  vars:
    - cluster_type: "{{ lookup('env', 'CLUSTER_TYPE') }}"
    - slackhook_path: "{{ lookup('env', 'CLUSTER_PROFILE_DIR') }}/slackhook"
    - packet_project_id: "{{ lookup('file', lookup('env', 'CLUSTER_PROFILE_DIR') + '/packet-project-id') }}"
    - packet_auth_token: "{{ lookup('file', lookup('env', 'CLUSTER_PROFILE_DIR') + '/packet-auth-token') }}"

  tasks:
  - name: check cluster type
    fail:
      msg: "Unsupported CLUSTER_TYPE '{{ cluster_type }}'"
    when: cluster_type != "packet"

  - name: create Packet host with error handling
    block:
    - name: create Packet host {{ packet_hostname }}
      packet_device:
        auth_token: "{{ packet_auth_token }}"
        project_id: "{{ packet_project_id }}"
        hostnames: "{{ packet_hostname }}"
        operating_system: centos_8
        plan: ${PACKET_PLAN}
        facility: any
        wait_for_public_IPv: 4
        wait_timeout: 1200
        state: active
        tags: "{{ 'PR:', lookup('env', 'PULL_NUMBER'), 'Job name:', lookup('env', 'JOB_NAME'), 'Job id:', lookup('env', 'PROW_JOB_ID') }}"
      register: hosts
      no_log: true
    - name: wait for ssh
      wait_for:
        delay: 5
        host: "{{ hosts.devices[0].public_ipv4 }}"
        port: 22
        state: started
        timeout: 900
    rescue:
    - name: Send notification message via Slack in case of failure
      slack:
        token: "{{ 'T027F3GAJ/B011TAG710V/' + lookup('file', slackhook_path) }}"
        msg: "Packet failure: *Setup*\nHostname: *{{ packet_hostname }}*\nError msg: {{ ansible_failed_result.msg }}\n"
        username: "OpenShift CI Packet"
        color: warning
        icon_emoji: ":failed:"
    - name: fail the play
      fail:
        msg: "ERROR: Packet setup failed."

  - name: save Packet IP
    local_action: copy content="{{ hosts.devices[0].public_ipv4 }}" dest="{{ lookup('env', 'SHARED_DIR') }}/server-ip"

  - name: write fix uid file
    copy:
      content: |
        # Ensure our UID, which is randomly generated, is in /etc/passwd. This is required
        # to be able to SSH.
        if ! whoami &> /dev/null; then
            if [ -x "\$(command -v nss_wrapper.pl)" ]; then
                grep -v -e ^default -e ^\$(id -u) /etc/passwd > "/tmp/passwd"
                echo "\${USER_NAME:-default}:x:\$(id -u):0:\${USER_NAME:-default} user:\${HOME}:/sbin/nologin" >> "/tmp/passwd"
                export LD_PRELOAD=libnss_wrapper.so
                export NSS_WRAPPER_PASSWD=/tmp/passwd
                export NSS_WRAPPER_GROUP=/etc/group
            elif [[ -w /etc/passwd ]]; then
                echo "\${USER_NAME:-default}:x:\$(id -u):0:\${USER_NAME:-default} user:\${HOME}:/sbin/nologin" >> "/etc/passwd"
            else
                echo "No nss wrapper, /etc/passwd is not writeable, and user matching this uid is not found."
                exit 1
            fi
        fi
      dest: "${SHARED_DIR}/fix-uid.sh"

  - name: write Packet common configuration file
    copy:
      content: |
        source "\${SHARED_DIR}/fix-uid.sh"

        # Initial check
        if [ "\${CLUSTER_TYPE}" != "packet" ]; then
            echo >&2 "Unsupported cluster type '\${CLUSTER_TYPE}'"
            exit 1
        fi

        IP=\$(cat "\${SHARED_DIR}/server-ip")
        SSHOPTS=(-o 'ConnectTimeout=5' -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null' -o 'ServerAliveInterval=90' -o LogLevel=ERROR -i "\${CLUSTER_PROFILE_DIR}/packet-ssh-key")

        # Checkout packet server
        for x in \$(seq 10) ; do
            test "\${x}" -eq 10 && exit 1
            ssh "\${SSHOPTS[@]}" "root@\${IP}" hostname && break
            sleep 10
        done
      dest: "${SHARED_DIR}/packet-conf.sh"
EOF

ansible-playbook packet-setup.yaml -e "packet_hostname=ipi-${NAMESPACE}-${JOB_NAME_HASH}-${BUILD_ID}"  |& gawk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'

Properties

Property Value Description
Resource requests (cpu) 1000m Used in .resources.requests of the pod running this step.
Resource requests (memory) 600Mi Used in .resources.requests of the pod running this step.
Resource limits (memory) 2Gi Used in .resources.limits of the pod running this step.

GitHub Link:

https://github.com/openshift/release/blob/master/ci-operator/step-registry/baremetalds/packet/setup/baremetalds-packet-setup-ref.yaml

Owners:

Approvers:

Source code for this page located on GitHub