Chef: This resource is written with Chef 12.5 and requires at least Chef 12.0[…] it will not work with Chef 11.x clients

Автор: | 15/09/2016
 

pic-chef-logoОшибка

Ошибка во время провижена Adobe Experience Manager (CQ5):


16:34:13.924 Starting Chef Client, version 11.14.6
16:34:17.226 Compiling Cookbooks…
16:34:17.237
16:34:17.237 ================================================================================
16:34:17.237 Recipe Compile Error in /home/chef/chef-solo/cookbooks-2/compat_resource/libraries/autoload.rb
16:34:17.237 ================================================================================
16:34:17.237
16:34:17.237 RuntimeError
16:34:17.237 ————
16:34:17.237 This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade.
16:34:17.237
16:34:17.238 Cookbook Trace:
16:34:17.238 —————
16:34:17.238 /home/chef/chef-solo/cookbooks-2/compat_resource/libraries/autoload.rb:2:in `<top (required)>’
16:34:17.238
16:34:17.238 Relevant File Content:
16:34:17.238 ———————-
16:34:17.238 /home/chef/chef-solo/cookbooks-2/compat_resource/libraries/autoload.rb:
16:34:17.238
16:34:17.238 1: unless Gem::Requirement.new(“>= 12.0”).satisfied_by?(Gem::Version.new(Chef::VERSION))
16:34:17.238 2>> raise “This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade.”
16:34:17.239 3: end

Подготовка

Получаем кухню:

$ git clone ssh://[email protected]:7999/rr.environments.git

Тут:

$ ls -l
total 48
-rw-rw-r-- 1 setevoy setevoy   988 вер 14 11:12 Berksfile
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 data_bags
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 environments
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 nodes
-rw-rw-r-- 1 setevoy setevoy  1726 вер 14 11:12 README.md
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 roles
-rw-rw-r-- 1 setevoy setevoy 10622 вер 14 11:12 rr-environment.kdbx
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 scripts
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 site-cookbooks
drwxrwxr-x 2 setevoy setevoy  4096 вер 14 11:12 ssh

Копируем ноду:

$ cp nodes/vmu-rr-auth1.emea.domain.local.json nodes/192.168.33.10.json

В другом окне консоли – запускаем Vagrant box:

$ cd ~/VMs/Vagrant/centos7 && vagrant up

На боксе – добавляем пользователя и ключ:

$ vagrant ssh
# adduser chef
# passwd chef
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
# mkdir /home/chef/.ssh && chown -R chef:chef /home/chef/

Копируем RSA ключ с рабочей машины:

$ ssh-copy-id -i ssh/id_rsa.pub [email protected]
The authenticity of host '192.168.33.10 (192.168.33.10)' can't be established.
ECDSA key fingerprint is 0d:b0:7b:f2:8a:be:34:7b:2c:f4:55:13:b4:5a:97:99.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

Проверяем:

$ ssh -i ssh/id_rsa [email protected] "uname -a"
Linux localhost.localdomain 3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Разрешаем пользователю chef выполнять через sudo всё и без пароля:

# visudo

Добавляем строку:

...
chef    ALL=(ALL:ALL) NOPASSWD:ALL
...

Проверка

Запускам knife-solo – пробуем воспроизвести ошибку с билд-агента:

$ knife solo bootstrap -i ssh/id_rsa [email protected]
WARNING: No knife configuration file found
Bootstrapping Chef...
...
Uploading the kitchen...
...
Starting Chef Client, version 11.8.2
Compiling Cookbooks...

================================================================================
Recipe Compile Error in /home/chef/chef-solo/cookbooks-2/compat_resource/libraries/autoload.rb
================================================================================

RuntimeError
------------
This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade.
...

Решение

С помощью --bootstrap-version – укажем версию Chef, которая будет устанавливаться на боксе.

Запуск knife выполняется с помощью bash-скрипта:

#!/usr/bin/env bash
set -xe

CQ_SERVER="$1"
CQ_SERVICE="$2" # cqauthor or cqpublish
SSH_KEY="ssh/id_rsa"
me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"

# Hack to fix WARNING: UNPROTECTED PRIVATE KEY FILE! error
chmod 600 ../$SSH_KEY

echo "[$me] Stop $CQ_SERVICE at $CQ_SERVER"
ssh -t -t -oStrictHostKeyChecking=no -i ../$SSH_KEY chef@$CQ_SERVER "echo chef | sudo -S service $CQ_SERVICE stop" || exit $?
echo "[$me] Remove /data"
ssh -t -t -oStrictHostKeyChecking=no -i ../$SSH_KEY chef@$CQ_SERVER "echo chef | sudo -S rm -rf /data/*" || exit $?
echo "[$me] Bootstrap CQ"
cd .. && knife solo bootstrap chef@$CQ_SERVER -i $SSH_KEY -P chef --no-host-key-verify || exit $?
echo "[$me] Completed"

Редактируем последнюю строку, и добавляем параметр --bootstrap-version 12.5:

...
cd .. && knife solo bootstrap chef@$CQ_SERVER -i $SSH_KEY -P chef --no-host-key-verify --bootstrap-version 12.5 || exit $?
...

Запускаем, проверяем:

$ ./go-cq-reprovision.sh 192.168.33.10 cqauthor
+ CQ_SERVER=192.168.33.10
+ CQ_SERVICE=cqauthor
...
url     https://packages.chef.io/stable/el/7/chef-12.5.1-1.el7.x86_64.rpm
version 12.5.1
...
Installing chef 12.5
...
 - start service service[CQ5-author]
 * simple_iptables_rule[system] action append (up to date)
 * cq5_statechecker[aem] action wait
Waiting for AEM to start at localhost:4502 ...
...
Waiting for AEM to start at localhost:4502 ...
AEM is now up and running, check it out!
 (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 91/133 resources updated in 3430.419996419 seconds
+ echo '[go-cq-reprovision.sh] Compleated'
[go-cq-reprovision.sh] Compleated

Готово.

P.S. Как же приятно переключится с проекта на Azure – на что-то более адекватное…