Merge pull request #6 from salt-formulas/update-verification
update-verification - user reclass.validat*
lgtm - these are already available
diff --git a/bootstrap.sh b/bootstrap.sh
index af5d7da..f6428ce 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -75,6 +75,7 @@
# salt
export SALT_MASTER=${SALT_MASTER:-127.0.0.1} # ip or fqdn
export MINION_ID=${MINION_ID:-${HOSTNAME}.${DOMAIN}}
+export MASTER_HOSTNAME=${MASTER_HOSTNAME:-${HOSTNAME}.${DOMAIN}}
# saltstack
BOOTSTRAP_SALTSTACK=${BOOTSTRAP_SALTSTACK:-True}
@@ -193,6 +194,24 @@
##########################################
# Main calls
+system_config_ssh_conf() {
+ for conf in ~/.ssh/config /root/.ssh/config; do
+ $SUDO mkdir -p $(dirname $conf)
+ if ! grep StrictHostKeyChecking $conf; then
+ # this should be used only in CI environment
+ echo -e "Host *\n\tStrictHostKeyChecking no\n" | $SUDO tee $conf >/dev/null
+ fi
+ done
+ if ! grep github.com ~/.ssh/known_hosts; then
+ ssh-keyscan -H github.com >> ~/.ssh/known_hosts || true
+ fi
+}
+
+system_config_salt_modules_prereq() {
+ # salt-formulas custom modules dependencies, etc:
+ $SUDO $PKGTOOL install -y iproute2 curl sudo apt-transport-https python-psutil python-apt python-m2crypto python-oauth python-pip &>/dev/null
+}
+
system_config_minion() {
log_info "System configuration salt minion"
}
@@ -200,15 +219,15 @@
system_config_master() {
log_info "System configuration salt master"
- # salt-formulas custom modules dependencies, etc:
- $SUDO $PKGTOOL install -y iproute2 curl sudo apt-transport-https python-psutil python-apt python-m2crypto python-oauth python-pip &>/dev/null
+ system_config_salt_modules_prereq
+ system_config_ssh_conf
$SUDO mkdir -p $RECLASS_ROOT/classes/service
- $SUDO mkdir -p /root/.ssh
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts || true
- echo -e "Host *\n\tStrictHostKeyChecking no\n" | $SUDO tee ~/.ssh/config >/dev/null
- echo -e "Host *\n\tStrictHostKeyChecking no\n" | $SUDO tee /root/.ssh/config >/dev/null
- echo "127.0.1.2 salt" | $SUDO tee -a /etc/hosts >/dev/null
+ $SUDO mkdir -p $RECLASS_ROOT/nodes/_generated
+
+ if ! grep '127.0.1.2.*salt' /etc/hosts; then
+ echo "127.0.1.2 salt" | $SUDO tee -a /etc/hosts >/dev/null
+ fi
which reclass || $SUDO $PKGTOOL install -y reclass
@@ -224,6 +243,10 @@
echo "Configuring salt-master ..."
+ if [[ $RECLASS_IGNORE_CLASS_NOTFOUND =~ ^(True|true|1|yes)$ ]]; then
+ IGNORE_CLASS_NOTFOUND="ignore_class_notfound: True"
+ fi
+
[ ! -d /etc/salt/master.d ] && mkdir -p /etc/salt/master.d
cat <<-EOF > /etc/salt/master.d/master.conf
file_roots:
@@ -238,6 +261,7 @@
reclass: &reclass
storage_type: yaml_fs
inventory_base_uri: ${RECLASS_ROOT}
+ ${IGNORE_CLASS_NOTFOUND}
ext_pillar:
- reclass: *reclass
master_tops:
@@ -252,6 +276,7 @@
pretty_print: True
output: yaml
inventory_base_uri: ${RECLASS_ROOT}
+ ${IGNORE_CLASS_NOTFOUND}
EOF
clone_reclass
@@ -266,31 +291,33 @@
#sed -ie "s#\(reclass_data_revision.\).*#\1 $RECLASS_BRANCH#" $(find nodes -name ${MASTER_HOSTNAME}.yml|tail -n1)
- mkdir -vp ${RECLASS_ROOT}/nodes
+ mkdir -vp ${RECLASS_ROOT}/nodes/_generated
CONFIG=$(find ${RECLASS_ROOT}/nodes -name ${MINION_ID}.yml| grep yml | tail -n1)
- CONFIG=${CONFIG:-${RECLASS_ROOT}/nodes/${MINION_ID}.yml}
+ CONFIG=${CONFIG:-${RECLASS_ROOT}/nodes/_generated/${MINION_ID}.yml}
if [[ $SALT_MASTER_BOOTSTRAP_MINIMIZED =~ ^(True|true|1|yes)$ || ! -f "${CONFIG}" ]]; then
cat <<-EOF > ${CONFIG}
classes:
- - service.git.client
- - system.linux.system.single
- - system.salt.master.single
- - system.salt.master.$FORMULAS_SOURCE
- - system.reclass.storage.salt
+ - cluster.${CLUSTER_NAME}.infra.config
parameters:
_param:
- reclass_data_repository: "$RECLASS_ADDRESS"
- reclass_data_revision: ${RECLASS_BRANCH:-master}
- salt_formula_branch: ${SALT_FORMULAS_BRANCH:-master}
- reclass_config_master: $SALT_MASTER
single_address: $SALT_MASTER
salt_master_host: $SALT_MASTER
salt_master_base_environment: $SALT_ENV
- linux_system_codename: $DISTRIB_CODENAME
+ salt_formula_branch: ${SALT_FORMULAS_BRANCH:-master}
+ reclass_data_revision: ${RECLASS_BRANCH:-master}
+ reclass_data_repository: "$RECLASS_ADDRESS"
+ reclass_config_master: $SALT_MASTER
+ linux_system_codename: ${DISTRIB_CODENAME}
+ cluster_name: ${CLUSTER_NAME}
+ cluster_domain: ${DOMAIN:-$CLUSTER_NAME.local}
linux:
system:
- name: $MINION_ID
- domain: $DOMAIN
+ name: ${HOSTNAME:-cfg01}
+ domain: ${DOMAIN:-$CLUSTER_NAME.local}
+ #reclass:
+ # storage:
+ # data_source:
+ # engine: local
# ########
EOF
@@ -562,13 +589,17 @@
# log_warn "Node verification before initialization failed."; cat /tmp/${MASTER_HOSTNAME}.pillar;
#fi
+
+ # workarond isolated and not fully bootstraped environments
+ PILLAR='{"salt":{"master":{"pillar":{"reclass":{"ignore_class_notfound": "'${RECLASS_IGNORE_CLASS_NOTFOUND:-False}'"}}}}, "reclass":{"storage":{"data_source":{"engine":"local"}}} }'
+
log_info "State: salt.master.env"
- if ! $SUDO salt-call ${SALT_OPTS} -linfo state.apply salt.master.env; then
+ if ! $SUDO salt-call ${SALT_OPTS} -linfo state.apply salt.master.env pillar="$PILLAR"; then
log_err "State salt.master.env failed, keep your eyes wide open."
fi
log_info "State: salt.master.pillar"
- retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.pillar pillar='{"reclass":{"storage":{"data_source":{"engine":"local"}}}}'
+ retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.pillar pillar="$PILLAR"
# Note: sikp reclass data dir states
# in order to avoid pull from configured repo/branch
@@ -576,19 +607,23 @@
pushd $RECLASS_ROOT
if [ $(git diff --name-only nodes | sort | uniq | wc -l) -ge 1 ]; then
git status || true
- log_warn "Locally modified $RECLASS_ROOT/nodes found. (Possibly salt-master minimized setup from salt-master-setup.sh call)"
+ log_warn "Locally modified $RECLASS_ROOT/nodes found. (Possibly salt-master minimized setup from bootstrap.sh call)"
log_info "Checkout HEAD state of $RECLASS_ROOT/nodes/*."
git checkout -- $RECLASS_ROOT/nodes || true
log_info "Re-Run states: salt.master.env and salt.master.pillar according the HEAD state."
log_info "State: salt.master.env"
- if ! $SUDO salt-call ${SALT_OPTS} -linfo state.apply salt.master.env; then
+ if ! $SUDO salt-call ${SALT_OPTS} -linfo state.apply salt.master.env pillar="$PILLAR"; then
log_err "State salt.master.env failed, keep your eyes wide open."
fi
log_info "State: salt.master.pillar"
- retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.pillar pillar='{"reclass":{"storage":{"data_source":{"engine":"local"}}}}'
+ retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.pillar pillar="$PILLAR"
fi
popd
+ # finally re-configure salt master conf, ie: may remove ignore_class_notfound option
+ log_info "State: salt.master.service"
+ $SUDO salt-call ${SALT_OPTS} state.apply salt.master.service || true
+
log_info "State: salt.master.storage.node"
set +e
# TODO: PLACEHOLDER TO TRIGGER NODE GENERATION THROUG SALT REACT.