Table des matières

Version : 2023.01

Dernière mise-à-jour : 2023/11/12 11:41

LDF702 - Installation du Chef Infra Server et du Chef Workstation

Contenu du Module

Infrastructure

L'infrastructure utilisée dans ce module est la suivante.

Type Machine FQDN IP OS Version CPUs RAM (Mo) HDD (Go) User MdP MdP root
VM chefserver.ittraining.loc 10.0.2.110 Ubuntu 18.04.6 LTS 8 8192 50 trainee trainee S/O
VM workstation.ittraining.loc 10.0.2.111 Ubuntu 18.04.6 LTS 8 8192 50 trainee trainee S/O

LAB #1 - Installer et Configurer Chef Infra Server

1.1 - Présentation

Rappelez-vous que Chef supporte de multiples OS en tant que clients :

Le Chef Infra Server nécessite une des distributions Linux suivantes :

Important - Notez que Chef Infra Server ne peut pas être installé sur Windows™.

La configuation minimale de Chef Infra Server est :

1.2 - Installation

Connectez-vous ensuite à votre VM ChefServer_10.0.2.110_SSH :

Devenez l'utilisateur root :

trainee@chefserver:~$ sudo su -
[sudo] password for trainee: trainee

Installez le paquet curl :

root@chefserver:~# apt update
...
root@chefserver:~# apt install curl -y
...

Créez maintenant deux répertoires à la racine du filesystem :

root@chefserver:~# mkdir /key
root@chefserver:~# mkdir /downloads

Téléchargez le paquet chef-server-core_13.0.17-1_amd64.deb vers le répertoire /downloads :

root@chefserver:~# wget -nv -P /downloads https://packages.chef.io/files/stable/chef-server/13.0.17/ubuntu/18.04/chef-server-core_13.0.17-1_amd64.deb
2023-10-30 13:16:56 URL:https://packages.chef.io/files/stable/chef-server/13.0.17/ubuntu/18.04/chef-server-core_13.0.17-1_amd64.deb [252269838/252269838] -> "/downloads/chef-server-core_13.0.17-1_amd64.deb" [1]

Installez le paquet chef-server-core_13.0.17-1_amd64.deb :

root@chefserver:~# dpkg -i /downloads/chef-server-core_13.0.17-1_amd64.deb
Selecting previously unselected package chef-server-core.
(Reading database ... 184142 files and directories currently installed.)
Preparing to unpack .../chef-server-core_13.0.17-1_amd64.deb ...
Unpacking chef-server-core (13.0.17-1) ...
Setting up chef-server-core (13.0.17-1) ...

1.3 - Configuration

Utilisez la commande chef-server-ctl reconfigure pour procéder à une configuration initiale de Chef Infra Server :

root@chefserver:~# chef-server-ctl reconfigure
...
Running handlers:
Running handlers complete
Chef Infra Client finished, 482/1028 resources updated in 05 minutes 44 seconds
Chef Server Reconfigured!

En utilisant la commande curl, vérifiez que Chef Infra Server est démarré :

root@chefserver:~# curl -D - http://localhost:8000/_status | grep "200 OK"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   483  100   483    0     0  HTTP/1.1 200 OK
 6616      0 --:--:-- --:--:-- --:--:--  6616

Créez maintenant l'utilisateur chefadmin ayant un mot de passe fenestros :

root@chefserver:~# chef-server-ctl user-create chefadmin Chef Admin infos@ittraining.team fenestros --filename /key/chefadmin.pem

Important - Remplacez l'adresse email infos@ittraining.team avec votre adresse email.

Créez ensuite l'organisation chefacademy associée à l'utilisateur chefadmin :

root@chefserver:~# chef-server-ctl org-create chefacademy "Chef Academy." --association_user chefadmin --filename /key/chefacademy.pem

Vérifiez que tous les services sont en cours de fonctionnement :

root@chefserver:~# chef-server-ctl service-list
bookshelf*
nginx*
oc_bifrost*
oc_id*
opscode-erchef*
opscode-expander*
opscode-solr4*
postgresql*
rabbitmq*
redis_lb*

Important - Le caractère * indique que le service fonctionne.

1.4 - Installation et Configuration de l'Interface Web

L'interface web de Chef Infra Server nécessite l'installation de chef-manage :

root@chefserver:~# chef-server-ctl install chef-manage
Starting Chef Infra Client, version 15.0.300
resolving cookbooks for run list: ["private-chef::add_ons_wrapper"]
Synchronizing Cookbooks:
  - private-chef (0.1.1)
  - runit (5.1.1)
  - enterprise (0.15.1)
  - yum-epel (3.3.0)
  - packagecloud (1.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 4 resources
Recipe: private-chef::add_ons_wrapper
  * ruby_block[addon_install_notification_chef-manage] action nothing (skipped due to action :nothing)
  * remote_file[/var/opt/opscode/local-mode-cache/chef-manage_3.3.66-1_amd64.deb] action create
    - create new file /var/opt/opscode/local-mode-cache/chef-manage_3.3.66-1_amd64.deb
    - update content in file /var/opt/opscode/local-mode-cache/chef-manage_3.3.66-1_amd64.deb from none to 9713b2
    (file sizes exceed 10000000 bytes, diff output suppressed)
  * ruby_block[locate_addon_package_chef-manage] action run
    - execute the ruby block locate_addon_package_chef-manage
  * apt_package[chef-manage] action install
    - install version 3.3.66-1 of package chef-manage
  * ruby_block[addon_install_notification_chef-manage] action run
    - execute the ruby block addon_install_notification_chef-manage

Running handlers:
-- Installed Add-On Package: chef-manage
  - #<Class:0x0000000004db2ed8>::AddonInstallHandler
Running handlers complete
Chef Infra Client finished, 4/5 resources updated in 47 seconds

Reconfigurez Chef Infra Server pour prendre en compte l'installation précédente :

root@chefserver:~# chef-server-ctl reconfigure
...
Running handlers:
Running handlers complete
Chef Infra Client finished, 52/553 resources updated in 01 minutes 03 seconds
Chef Server Reconfigured!

Procédez ensuite à la configuration de chef-manage :

root@chefserver:~# chef-manage-ctl reconfigure
...
Infra Phase complete, 97/273 resources updated in 38 seconds
[2023-10-30T13:40:51+01:00] WARN: This release of Chef Infra Client became end of life (EOL) on May 1st 2023. Please update to a supported release to receive new features, bug fixes, and security updates.
chef-manage Reconfigured!

Connectez-vous ensuite à votre VM ChefServer_10.0.2.110_VNC.

Ouvrez le navigateur Web et naviguez à l'adresse 10.0.2.110. Acceptez ensuite le certificat :

Vous obtiendrez :

Renseignez l'utilisateur chefadmin et le mot de passe fenestros puis cliquez sur le bouton Sign In :

Vous obtiendrez :

Important - Notez que pour l'instant aucun nœud ne soit renseigné.

LAB #2 - Installer et Configurer Chef Workstation

2.1 - Présentation

Rappelez-vous que Chef Workstation contient les exécutables suivantes :

La configuation minimale de Chef Workstation est :

La configuation recommendée de Chef Workstation est :

2.2 - Installation et Configuration

Connectez-vous ensuite à votre VM ChefServer_10.0.2.110_SSH.

Connectez-vous à votre Chef Workstation à partir de votre Chef Infra Server en utilisant l'IP associée à votre numéro de stagiaire :

root@chefserver:/key# ssh -l trainee 10.0.2.111
trainee@10.0.2.111's password: 
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-150-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Expanded Security Maintenance for Infrastructure is not enabled.

0 updates can be applied immediately.

Enable ESM Infra to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

New release '20.04.6 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2023.
Last login: Mon Oct 30 14:39:59 2023 from 10.0.2.110

Créez le répertoire /downloads :

trainee@workstation:~$ sudo su -
[sudo] password for trainee: trainee
root@workstation:~# mkdir /downloads

Téléchargez le paquet chef-workstation_0.14.16-1_amd64.deb vers le répertoire /downloads :

root@workstation:~# wget -nv -P /downloads https://packages.chef.io/files/stable/chef-workstation/0.14.16/ubuntu/18.04/chef-workstation_0.14.16-1_amd64.deb
2023-10-30 15:00:10 URL:https://packages.chef.io/files/stable/chef-workstation/0.14.16/ubuntu/18.04/chef-workstation_0.14.16-1_amd64.deb [152223072/152223072] -> "/downloads/chef-workstation_0.14.16-1_amd64.deb" [1]

Installez le paquet chef-workstation_0.14.16-1_amd64.deb :

root@workstation:~# dpkg -i /downloads/chef-workstation_0.14.16-1_amd64.deb
Selecting previously unselected package chef-workstation.
(Reading database ... 184129 files and directories currently installed.)
Preparing to unpack .../chef-workstation_0.14.16-1_amd64.deb ...
Unpacking chef-workstation (0.14.16-1) ...
Setting up chef-workstation (0.14.16-1) ...

The Chef Workstation App is available for you to try.

Launch the App by running 'chef-workstation-app'.
The App will then be available in the system tray.

Thank you for installing Chef Workstation!
You can find some tips on getting started at https://chef.sh/

Configurez Ruby :

root@workstation:~# which ruby

root@workstation:~# eval "$(chef shell-init bash)"

root@workstation:~# echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile

root@workstation:~# chef shell-init bash
export PATH="/opt/chef-workstation/bin:/root/.chefdk/gem/ruby/2.6.0/bin:/opt/chef-workstation/embedded/bin:/opt/chef-workstation/bin:/root/.chefdk/gem/ruby/2.6.0/bin:/opt/chef-workstation/embedded/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/chef-workstation/gitbin:/opt/chef-workstation/gitbin"
export GEM_ROOT="/opt/chef-workstation/embedded/lib/ruby/gems/2.6.0"
export GEM_HOME="/root/.chefdk/gem/ruby/2.6.0"
export GEM_PATH="/root/.chefdk/gem/ruby/2.6.0:/opt/chef-workstation/embedded/lib/ruby/gems/2.6.0"
_chef_comp() {
    local COMMANDS="exec env gem generate shell-init install update push push-archive show-policy diff export clean-policy-revisions clean-policy-cookbooks delete-policy-group delete-policy undelete describe-cookbook provision"
    COMPREPLY=($(compgen -W "$COMMANDS" -- ${COMP_WORDS[COMP_CWORD]} ))
}
complete -F _chef_comp chef

root@workstation:~# which ruby
/opt/chef-workstation/embedded/bin/ruby

Connectez-vous ensuite à votre VM ChefServer_10.0.2.110_VNC.

Ouvrez le navigateur Web et naviguez à l'adresse 10.0.2.110 :

Cliquez sur l'organisation chefacademy puis sur l'icône de la roue dentée à droite :

Cliquez sur le bouton Download Starter Kit :

2.3 - Configuration

Connectez-vous ensuite à votre VM ChefServer_10.0.2.110_SSH.

Copiez le fichier chef-starter.zip à partir de Chef Infra Server vers le répertoire courant de votre Chef Workstation :

root@workstation:~# scp trainee@10.0.2.110:/home/trainee/Downloads/chef-starter.zip .
The authenticity of host '10.0.2.110 (10.0.2.110)' can't be established.
ECDSA key fingerprint is SHA256:RRU4Tim5H5klLxXUa8hyodLq5DSGrKuZ07jziXLVmFw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.2.110' (ECDSA) to the list of known hosts.
trainee@10.0.2.110's password: 
chef-starter.zip                                    100% 7767    10.8MB/s   00:00 

Décompressez le fichier :

root@workstation:~# unzip chef-starter.zip 
Archive:  chef-starter.zip
  inflating: chef-repo/.gitignore    
  inflating: chef-repo/README.md     
   creating: chef-repo/cookbooks/
  inflating: chef-repo/cookbooks/chefignore  
   creating: chef-repo/cookbooks/starter/
   creating: chef-repo/cookbooks/starter/attributes/
  inflating: chef-repo/cookbooks/starter/attributes/default.rb  
   creating: chef-repo/cookbooks/starter/files/
   creating: chef-repo/cookbooks/starter/files/default/
  inflating: chef-repo/cookbooks/starter/files/default/sample.txt  
  inflating: chef-repo/cookbooks/starter/metadata.rb  
   creating: chef-repo/cookbooks/starter/recipes/
  inflating: chef-repo/cookbooks/starter/recipes/default.rb  
   creating: chef-repo/cookbooks/starter/templates/
   creating: chef-repo/cookbooks/starter/templates/default/
  inflating: chef-repo/cookbooks/starter/templates/default/sample.erb  
   creating: chef-repo/.chef/
   creating: chef-repo/roles/
  inflating: chef-repo/.chef/config.rb  
  inflating: chef-repo/roles/starter.rb  
  inflating: chef-repo/.chef/chefadmin.pem 

La configuration se trouve dans le fichier chef-repo/.chef/config.rb :

root@workstation:~# ls -l chef-repo/.chef
total 8
-rw-r--r-- 1 root root 1674 oct.  30 15:07 chefadmin.pem
-rw-r--r-- 1 root root  425 oct.  30 15:07 config.rb

En consultant ce fichier, vous constaterez l'URL du Chef Infra Server - https://chefserver/organizations/chefacademy :

root@workstation:~# cat chef-repo/.chef/config.rb 
# See https://docs.chef.io/workstation/config_rb/ for more information on knife configuration options

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "chefadmin"
client_key               "#{current_dir}/chefadmin.pem"
chef_server_url          "https://chefserver/organizations/chefacademy"
cookbook_path            ["#{current_dir}/../cookbooks"]

Éditez donc le fichier /etc/hosts pour pointer l'adresse 10.0.2.110 vers chefserver.ittraining.loc :

root@workstation:~# vi /etc/hosts
root@workstation:~# cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       workstation
10.0.2.110      chefserver.ittraining.loc   chefserver
10.0.2.111      workstation.ittraining.loc  workstation

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Placez-vous dans le répertoire /root/chef-repo/.chef/ et récupérez le certificat de Chef Infra Server en utilisant la commande knife :

root@workstation:~# cd chef-repo/.chef/ 
root@workstation:~/chef-repo/.chef# knife ssl fetch
WARNING: Certificates from chefserver will be fetched and placed in your trusted_cert
         directory (/root/chef-repo/.chef/trusted_certs).
         
         Knife has no means to verify these are the correct certificates. You should
         verify the authenticity of these certificates after downloading.
Adding certificate for chefserver in /root/chef-repo/.chef/trusted_certs/chefserver.crt

Vérifiez ensuite le certificat reçu :

root@workstation:~/chef-repo/.chef# knife ssl check
Connecting to host chefserver:443
Successfully verified certificates from `chefserver'

Copyright © 2023 Hugh Norris.