copr-builders: subscribe them using a custom script
The community general role seems to be entirely broken, keeping a lot of mess after itself. To be reported later.
This commit is contained in:
parent
726a788721
commit
8c4b4ae332
2 changed files with 96 additions and 23 deletions
83
roles/copr/backend/files/provision/copr-rh-subscribe.sh
Executable file
83
roles/copr/backend/files/provision/copr-rh-subscribe.sh
Executable file
|
@ -0,0 +1,83 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
echo >&2 "ERROR: $*" && exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
show_help()
|
||||||
|
{
|
||||||
|
cat <<EOHELP >&2
|
||||||
|
Usage: $0 --pool-id POOL_ID --user USER --pass PASS --system NAME
|
||||||
|
EOHELP
|
||||||
|
|
||||||
|
test -z "$1" || exit "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# handle no arguments
|
||||||
|
test ${#@} -eq 0 && show_help 1
|
||||||
|
|
||||||
|
ARGS=$(getopt -o "h" -l "pool-id:,user:,pass:,system:,help" -n "getopt" -- "$@") \
|
||||||
|
|| show_help 1
|
||||||
|
eval set -- "$ARGS"
|
||||||
|
|
||||||
|
option_variable()
|
||||||
|
{
|
||||||
|
# Function to convert '--some-option' to '$opt_some_option".
|
||||||
|
opt=$1
|
||||||
|
opt=${1##--}
|
||||||
|
opt=${opt##-}
|
||||||
|
opt=${opt//-/_}
|
||||||
|
option_variable_result=opt_$opt
|
||||||
|
}
|
||||||
|
|
||||||
|
opt_system=
|
||||||
|
opt_user=
|
||||||
|
opt_pass=
|
||||||
|
opt_pool_id=
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
show_help 0
|
||||||
|
;;
|
||||||
|
|
||||||
|
--pool-id|--user|--pass|--system)
|
||||||
|
option_variable "$1"
|
||||||
|
eval "$option_variable_result=\$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
|
||||||
|
--) shift; break;; # end
|
||||||
|
*) echo "programmer mistake ($1)" >&2; exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
set -x
|
||||||
|
provided=true
|
||||||
|
|
||||||
|
for i in system user pass pool_id; do
|
||||||
|
varname=opt_$i
|
||||||
|
if eval 'test -z "$'"$varname"'"'; then
|
||||||
|
provided=false
|
||||||
|
echo >&2 "$varname required"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
$provided || die "some options missing"
|
||||||
|
|
||||||
|
try_indefinitely()
|
||||||
|
{
|
||||||
|
cmd=( "$@" )
|
||||||
|
while :; do
|
||||||
|
if "${cmd[@]}"; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
try_indefinitely subscription-manager register --force \
|
||||||
|
--username "$opt_user" \
|
||||||
|
--password "$opt_pass" \
|
||||||
|
--name "$opt_system"
|
||||||
|
try_indefinitely subscription-manager attach --pool "$opt_pool_id"
|
|
@ -86,30 +86,20 @@
|
||||||
# subscription-manager by default.
|
# subscription-manager by default.
|
||||||
when: "'subscription-manager' not in ansible_facts.packages"
|
when: "'subscription-manager' not in ansible_facts.packages"
|
||||||
|
|
||||||
|
- name: install the subscription-manager script
|
||||||
|
copy:
|
||||||
|
src: copr-rh-subscribe.sh
|
||||||
|
dest: /usr/local/bin/copr-rh-subscribe.sh
|
||||||
|
|
||||||
- name: Activate Red Hat Subscription
|
- name: Activate Red Hat Subscription
|
||||||
community.general.redhat_subscription:
|
shell:
|
||||||
state: present
|
cmd: >
|
||||||
username: copr-team
|
/usr/local/bin/copr-rh-subscribe.sh \
|
||||||
force_register: true
|
--pool-id 8a85f9a17c71102f017ce611251c770f \
|
||||||
password: "{{ copr_red_hat_subscription_password }}"
|
--user copr-team \
|
||||||
consumer_name: "{{ lookup('env', 'RESALLOC_NAME') | default('unknown-builder') }}"
|
--pass "{{ copr_red_hat_subscription_password }}" \
|
||||||
server_hostname: subscription.rhsm.redhat.com
|
--system "{{ lookup('env', 'RESALLOC_NAME') | default('unknown-builder') }}"
|
||||||
pool_ids:
|
no_log: true
|
||||||
- "8a85f9a17c71102f017ce611251c770f"
|
|
||||||
when:
|
|
||||||
- prepare_base_image is not defined
|
|
||||||
- copr_red_hat_subscription_password is defined
|
|
||||||
tags:
|
|
||||||
- red_hat_subscription
|
|
||||||
ignore_errors: true
|
|
||||||
register: subscription
|
|
||||||
|
|
||||||
- name: Cleanup subscription before failure
|
|
||||||
shell: subscription-manager unregister
|
|
||||||
when: subscription.failed
|
|
||||||
|
|
||||||
- fail: msg="Could not subscribe"
|
|
||||||
when: subscription.failed
|
|
||||||
|
|
||||||
- name: install copr-builder and other latest packages
|
- name: install copr-builder and other latest packages
|
||||||
dnf: state=latest pkg={{ packages }}
|
dnf: state=latest pkg={{ packages }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue