From 77226079874216a22563cff089fcc4b2211bf30d Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 27 May 2018 10:00:01 -0300 Subject: Ansible support at init and newnode --- lib/hydra/misc | 1 + share/config/puppet/nodo.example.org.yaml | 2 -- share/config/puppet/secrets/nodo.example.org.yaml | 8 -------- share/hydra/init | 7 ++++++- share/hydra/newnode | 24 ++++++++++++++++++----- share/puppet/nodo.example.org.yaml | 2 ++ share/puppet/secrets/nodo.example.org.yaml | 8 ++++++++ 7 files changed, 36 insertions(+), 16 deletions(-) delete mode 100644 share/config/puppet/nodo.example.org.yaml delete mode 100644 share/config/puppet/secrets/nodo.example.org.yaml create mode 100644 share/puppet/nodo.example.org.yaml create mode 100644 share/puppet/secrets/nodo.example.org.yaml diff --git a/lib/hydra/misc b/lib/hydra/misc index 77c2988..2c5789b 100644 --- a/lib/hydra/misc +++ b/lib/hydra/misc @@ -176,6 +176,7 @@ function hydra_hiera_query { local param="$2" # Build basic query command + # There might be weird hiera errors, so that's why we're doing a "2> /dev/null" redirection hiera="hiera --config $HYDRA_FOLDER/puppet/hiera.yaml" hiera_params="settings::confdir=$HYDRA_FOLDER/puppet ::clientcert=$node" role="`$hiera nodo::role $hiera_params 2> /dev/null`" diff --git a/share/config/puppet/nodo.example.org.yaml b/share/config/puppet/nodo.example.org.yaml deleted file mode 100644 index 65aee56..0000000 --- a/share/config/puppet/nodo.example.org.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -nodo::role: 'virtual' diff --git a/share/config/puppet/secrets/nodo.example.org.yaml b/share/config/puppet/secrets/nodo.example.org.yaml deleted file mode 100644 index b2242bd..0000000 --- a/share/config/puppet/secrets/nodo.example.org.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -# -# Backup -# -# Example config: -# -# nodo::subsystem::backup::encryptkey : "FIXME" -# nodo::subsystem::backup::password : 'FIXME using hiera-eyaml' diff --git a/share/hydra/init b/share/hydra/init index 80dd449..3cf3074 100755 --- a/share/hydra/init +++ b/share/hydra/init @@ -107,12 +107,17 @@ else # Create puppet repository if [ ! -d "$BASEDIR/puppet" ]; then echo "Cloning initial puppet repository..." - git clone git://git.fluxo.info/puppet-bootstrap.git $BASEDIR/puppet + git clone https://git.fluxo.info/puppet-bootstrap $BASEDIR/puppet # Config puppet echo "Configuring puppet repository..." hydra_bootstrap_config $BASEDIR/puppet fi + + # Create ansible repository + mkdir -p $BASEDIR/ansible + cp -r $APP_BASE/share/ansible $BASEDIR/ansible + hydra_git_init $BASEDIR/ansible fi # Reparse basedir to force absolute folder diff --git a/share/hydra/newnode b/share/hydra/newnode index 96861f6..78cd6cb 100755 --- a/share/hydra/newnode +++ b/share/hydra/newnode @@ -51,10 +51,12 @@ if [ ! -z "$ROLE" ]; then fi # Set YAML template -if [ -e "$HYDRA_FOLDER/config/puppet/nodo.example.org.yaml" ]; then +if [ -e "$HYDRA_FOLDER/puppet/nodo.example.org.yaml" ]; then + YAML="$HYDRA_FOLDER/puppet/nodo.example.org.yaml" +elif [ -e "$HYDRA_FOLDER/config/puppet/nodo.example.org.yaml" ]; then YAML="$HYDRA_FOLDER/config/puppet/nodo.example.org.yaml" else - YAML="$APP_BASE/share/config/puppet/nodo.example.org.yaml" + YAML="$APP_BASE/share/puppet/nodo.example.org.yaml" fi # Copy YAML template @@ -67,10 +69,12 @@ if [ ! -z "$ROLE" ]; then fi # Set secret YAML template -if [ -e "$HYDRA_FOLDER/config/puppet/secrets/nodo.example.org.yaml" ]; then +if [ -e "$HYDRA_FOLDER/puppet/secrets/nodo.example.org.yaml" ]; then + YAML="$HYDRA_FOLDER/puppet/secrets/nodo.example.org.yaml" +elif [ -e "$HYDRA_FOLDER/config/puppet/secrets/nodo.example.org.yaml" ]; then YAML="$HYDRA_FOLDER/config/puppet/secrets/nodo.example.org.yaml" else - YAML="$APP_BASE/share/config/puppet/secrets/nodo.example.org.yaml" + YAML="$APP_BASE/share/puppet/secrets/nodo.example.org.yaml" fi # Setup secret YAML template @@ -90,12 +94,19 @@ echo "" >> $HYDRA_FOLDER/puppet/config/secrets/node/$NODE.yaml keyringer $HYDRA decrypt nodes/$NODE/gpg/key.passwd | \ hydra fluxo eyaml $NODE encrypt --stdin -o block -q -l nodo::subsystem::backup::password >> $HYDRA_FOLDER/puppet/config/secrets/node/$NODE.yaml -echo "" >> $HYDRA_FOLDER/puppet/config/secrets/node/$NODE.yam +echo "" >> $HYDRA_FOLDER/puppet/config/secrets/node/$NODE.yaml # Add Borg passphrase into secret node config keyringer $HYDRA decrypt nodes/$NODE/borg/key.passwd | \ hydra fluxo eyaml $NODE encrypt --stdin -o block -q -l nodo::subsystem::backup::borg::password >> $HYDRA_FOLDER/puppet/config/secrets/node/$NODE.yaml +# Ansible config +if [ -e "$HYDRA_FOLDER/ansible/inventories/production/hosts" ]; then + echo "$NODE" >> $HYDRA_FOLDER/ansible/inventories/production/hosts +elif [ -e "$HYDRA_FOLDER/ansible/inventories/hosts" ]; then + echo "$NODE" >> $HYDRA_FOLDER/ansible/inventories/hosts +fi + # Add to git ( cd $HYDRA_FOLDER/puppet @@ -105,4 +116,7 @@ hydra fluxo eyaml $NODE encrypt --stdin -o block -q -l nodo::subsystem::backup:: #if [ -e 'manifests/site.pp' ]; then # git add manifests/site.pp #fi + + cd $HYDRA_FOLDER/ansible + git add . ) diff --git a/share/puppet/nodo.example.org.yaml b/share/puppet/nodo.example.org.yaml new file mode 100644 index 0000000..65aee56 --- /dev/null +++ b/share/puppet/nodo.example.org.yaml @@ -0,0 +1,2 @@ +--- +nodo::role: 'virtual' diff --git a/share/puppet/secrets/nodo.example.org.yaml b/share/puppet/secrets/nodo.example.org.yaml new file mode 100644 index 0000000..b2242bd --- /dev/null +++ b/share/puppet/secrets/nodo.example.org.yaml @@ -0,0 +1,8 @@ +--- +# +# Backup +# +# Example config: +# +# nodo::subsystem::backup::encryptkey : "FIXME" +# nodo::subsystem::backup::password : 'FIXME using hiera-eyaml' -- cgit v1.2.3