Commit 5ecb524e authored by Walter Heck's avatar Walter Heck

Control wether to run puppet agent automatically after a node is registered to...

Control wether to run puppet agent automatically after a node is registered to the foreman when deploying with vagrant
parent 8b37ad72
Pipeline #369 passed with stages
in 2 minutes and 56 seconds
......@@ -19,6 +19,7 @@ ENV['OT_GROUP_MAPPING'] = ENV['OT_GROUP_MAPPING'] || "elasticsearch." + ENV['OT_
"gitlab." + ENV['OT_DOMAIN'] + "=OpsTheater/Gitlab " +
"mysql." + ENV['OT_DOMAIN'] + "=OpsTheater/MySQL"
ENV['OT_RUN_PUPPET_AUTOMATICALLY'] = ENV['OT_RUN_PUPPET_AUTOMATICALLY'] || 'true'
if defined? Oscar
# call ConfigBuilder.load with :yaml_erb directly so we can have erb parse the
......
......@@ -85,6 +85,7 @@ roles:
env:
OT_DOMAIN: <%= ENV['OT_DOMAIN'] %>
OT_GROUP_MAPPING: <%= ENV['OT_GROUP_MAPPING'] %>
OT_RUN_PUPPET_AUTOMATICALLY: <%= ENV['OT_RUN_PUPPET_AUTOMATICALLY'] %>
foss-puppet-agent-rhel7:
provisioners:
......
......@@ -4,27 +4,21 @@ echo "Running foreman-register-agent.sh"
/bin/yum install -y jq
/opt/puppetlabs/bin/puppet agent -t --noop
echo "OT_GROUP_MAPPING: ${OT_GROUP_MAPPING}"
echo "OT_DOMAIN: ${OT_DOMAIN}"
for X in $OT_GROUP_MAPPING
do
FQDN=$(echo $X | awk -F "=" '{print $1}' )
HOSTGROUP=$(echo $X | awk -F "=" '{print $2}' )
HOSTNAME=`hostname -f`
echo "X: ${X}"
echo "fqdn: ${FQDN}"
echo "hostgroup: ${HOSTGROUP}"
echo "hostname: ${HOSTNAME}"
if [ "${FQDN}" == "${HOSTNAME}" ]; then
HOSTID=`curl -k -s -u opstheater:opstheater "Accept: version=2,application/json" -H "Content-Type: application/json" -d "{\"search\":\"\`hostname -f\`\"}" -X GET https://master.${OT_DOMAIN}/api/hosts | jq .results[0].id`
HOSTGROUPID=`curl -k -s -u opstheater:opstheater "Accept: version=2,application/json" -H "Content-Type: application/json" -d "{\"search\":\"${HOSTGROUP}\"}" -X GET https://master.${OT_DOMAIN}/api/hostgroups | jq .results[0].id`
echo "Host id: ${HOSTID}"
echo "Hostgroup id: ${HOSTGROUPID}"
curl -k -s -u opstheater:opstheater "Accept: version=2,application/json" -H "Content-Type: application/json" -d "{\"host\":{\"hostgroup_id\":\"${HOSTGROUPID}\"}}" -X PUT https://master.${OT_DOMAIN}/api/hosts/${HOSTID}
echo "curl result: $?"
break
fi
done
if [ "${OT_RUN_PUPPET_AUTOMATICALLY}" == "true" ]; then
/opt/puppetlabs/bin/puppet agent -t
fi
echo "Finishing foreman-register-agent.sh"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment