Commit 9b5a0e57 authored by Walter Heck's avatar Walter Heck

Move the script for puppet agent registration to it's own file

the script that is used by vagrant to register an agent to it's foreman is now a separate file to make it easier
parent b909db3c
......@@ -74,14 +74,11 @@ roles:
puppet-agent-register-foreman:
provisioners:
-
type: shell
inline: |-
/bin/yum install -y jq
/opt/puppetlabs/bin/puppet agent -t --noop
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.opstheater.vm/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\":\"OpsTheater Infra/Elasticsearch\"}" -X GET https://master.opstheater.vm/api/hostgroups | jq .results[0].id`
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.opstheater.vm/api/hosts/${HOSTID}
- type: shell
path: files/foreman-register-agent.sh
env:
OT_DOMAIN: <%= ENV['OT_DOMAIN'] %>
GIT_BRANCH: <%= ENV['OT_GROUP_MAPPING'] %>
foss-puppet-agent-rhel7:
provisioners:
......
#!/bin/bash
/bin/yum install -y jq
/opt/puppetlabs/bin/puppet agent -t --noop
for X in "${OT_GROUP_MAPPING[@]}"
do
FQDN=$(echo $X | awk -F "=" '{print $1}' )
HOSTGROUP=$(echo $X | awk -F "=" '{print $2}' )
if [[ FQDN -eq `hostname -f` ]]; 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`
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}
break
fi
done
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