diff options
Diffstat (limited to 'share/hydra/newnode')
-rwxr-xr-x | share/hydra/newnode | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/share/hydra/newnode b/share/hydra/newnode index 7cb7ae4..e78b9bb 100755 --- a/share/hydra/newnode +++ b/share/hydra/newnode @@ -32,10 +32,8 @@ if [ -z "$NODE" ]; then elif [ ! -e "$HYDRA_FOLDER/config/domain" ]; then echo "fatal: please configure your domain at $HYDRA_FOLDER/config/domain" exit 1 -elif [ ! -f "$NODES" ]; then - echo "fatal: $NODES not found" - exit 1 -elif grep -qe "^import \"nodes/$NODE.pp\"$" $NODES &> /dev/null; then +#elif grep -qe "^import \"nodes/$NODE.pp\"$" $NODES &> /dev/null; then +elif [ -e "$HYDRA_FOLDER/puppet/manifest/nodes/$NODE.pp" ]; then echo "fatal: node $NODE already defined" exit 1 fi @@ -43,8 +41,15 @@ fi # Domain DOMAIN="`cat $HYDRA_FOLDER/config/domain`" +# Check if node was given by fqdn or just hostname +if ! echo $NODE | grep -q '\.'; then + NODE="$NODE.$DOMAIN" +fi + # Create node -echo "import \"nodes/$NODE.$DOMAIN.pp\"" >> $NODES +if [ -e "$NODES" ]; then + echo "import \"nodes/$NODE.pp\"" >> $NODES +fi # Set YAML template if [ -e "$HYDRA_FOLDER/config/templates/node/nodo.example.org.yaml" ]; then @@ -61,19 +66,26 @@ else fi # Copy YAML template -mkdir -p $HYDRA_FOLDER/puppet/hiera/production/domain/$DOMAIN/node -cp $YAML $HYDRA_FOLDER/puppet/hiera/production/domain/$DOMAIN/node/$NODE.$DOMAIN.yaml +mkdir -p $HYDRA_FOLDER/puppet/hiera/node +cp $YAML $HYDRA_FOLDER/puppet/hiera/node/$NODE.yaml + +# Setup secret YAML template +mkdir -p $HYDRA_FOLDER/puppet/hiera/secrets/node +echo "---" > $HYDRA_FOLDER/puppet/hiera/secrets/node/$NODE.yaml # Copy node template mkdir -p $HYDRA_FOLDER/puppet/manifests/nodes -cp $PP $HYDRA_FOLDER/puppet/manifests/nodes/$NODE.$DOMAIN.pp +cp $PP $HYDRA_FOLDER/puppet/manifests/nodes/$NODE.pp # Edit the template -sed -i -e "s/nodename/$NODE/g" $HYDRA_FOLDER/puppet/manifests/nodes/$NODE.pp -sed -i -e "s/example.org/$DOMAIN/g" $HYDRA_FOLDER/puppet/manifests/nodes/$NODE.pp +sed -i -e "s/nodename.example.org/$NODE/g" $HYDRA_FOLDER/puppet/manifests/nodes/$NODE.pp # Add to git ( cd $HYDRA_FOLDER/puppet - git add manifests/site.pp manifests/nodes/$NODE.pp hiera/production/domain/$DOMAIN/node/$NODE.$DOMAIN.yaml + git add manifests/nodes/$NODE.pp hiera/node/$NODE.yaml hiera/secrets/node/$NODE.yaml + + if [ -e 'manifests/site.pp' ]; then + git add manifests/site.pp + fi ) |