10:231 ; ˆl–Ðz¾”ji?u4 \¸î*bѿ „šuÿÁa–Ãa¾”*j"T†À·q¶ÔÅ£Æ0¿ # Copyright (C) 2012 Hewlett-Packard Development Company, L.P. # # Author: Avishai Ish-Shalom # Author: Mike Moulton # Author: Juerg Haefliger # # This file is part of cloud-init. See LICENSE file for license information. """Chef: module that configures, starts and installs chef.""" import itertools import json import logging import os from typing import List from cloudinit import subp, temp_utils, templater, url_helper, util from cloudinit.cloud import Cloud from cloudinit.config import Config from cloudinit.config.schema import MetaSchema from cloudinit.distros import Distro from cloudinit.settings import PER_ALWAYS RUBY_VERSION_DEFAULT = "1.8" CHEF_DIRS = tuple( [ "/etc/chef", "/var/log/chef", "/var/lib/chef", "/var/cache/chef", "/var/backups/chef", "/var/run/chef", ] ) REQUIRED_CHEF_DIRS = tuple( [ "/etc/chef", ] ) # Used if fetching chef from a omnibus style package OMNIBUS_URL = "https://www.chef.io/chef/install.sh" OMNIBUS_URL_RETRIES = 5 CHEF_VALIDATION_PEM_PATH = "/etc/chef/validation.pem" CHEF_FB_PATH = "/etc/chef/firstboot.json" CHEF_RB_TPL_DEFAULTS = { # These are ruby symbols... "ssl_verify_mode": ":verify_none", "log_level": ":info", # These are not symbols... "log_location": "/var/log/chef/client.log", "validation_key": CHEF_VALIDATION_PEM_PATH, "validation_cert": None, "client_key": "/etc/chef/client.pem", "json_attribs": CHEF_FB_PATH, "file_cache_path": "/var/cache/chef", "file_backup_path": "/var/backups/chef", "pid_file": "/var/run/chef/client.pid", "show_time": True, "encrypted_data_bag_secret": None, } CHEF_RB_TPL_BOOL_KEYS = frozenset(["show_time"]) CHEF_RB_TPL_PATH_KEYS = frozenset( [ "log_location", "validation_key", "client_key", "file_cache_path", "json_attribs", "pid_file", "encrypted_data_bag_secret", ] ) CHEF_RB_TPL_KEYS = frozenset( itertools.chain( CHEF_RB_TPL_DEFAULTS.keys(), CHEF_RB_TPL_BOOL_KEYS, CHEF_RB_TPL_PATH_KEYS, [ "server_url", "node_name", "environment", "validation_name", "chef_license", ], ) ) CHEF_RB_PATH = "/etc/chef/client.rb" CHEF_EXEC_PATH = "/usr/bin/chef-client" CHEF_EXEC_DEF_ARGS = tuple(["-d", "-i", "1800", "-s", "20"]) LOG = logging.getLogger(__name__) meta: MetaSchema = { "id": "cc_chef", "distros": ["all"], "frequency": PER_ALWAYS, "activate_by_schema_keys": ["chef"], } def post_run_chef(chef_cfg): delete_pem = util.get_cfg_option_bool( chef_cfg, "delete_validation_post_exec", default=False ) if delete_pem and os.path.isfile(CHEF_VALIDATION_PEM_PATH): os.unlink(CHEF_VALIDATION_PEM_PATH) def get_template_params(iid, chef_cfg): params = CHEF_RB_TPL_DEFAULTS.copy() # Allow users to overwrite any of the keys they want (if they so choose), # when a value is None, then the value will be set to None and no boolean # or string version will be populated... for k, v in chef_cfg.items(): if k not in CHEF_RB_TPL_KEYS: LOG.debug("Skipping unknown chef template key '%s'", k) continue if v is None: params[k] = None else: # This will make the value a boolean or string... if k in CHEF_RB_TPL_BOOL_KEYS: params[k] = util.get_cfg_option_bool(chef_cfg, k) else: params[k] = util.get_cfg_option_str(chef_cfg, k) # These ones are overwritten to be exact values... params.update( { "generated_by": util.make_header(), "node_name": util.get_cfg_option_str( chef_cfg, "node_name", default=iid ), "environment": util.get_cfg_option_str( chef_cfg, "environmen