puppet_agent_install.sh 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #*
  3. #/*
  4. # * Licensed to the Apache Software Foundation (ASF) under one
  5. # * or more contributor license agreements. See the NOTICE file
  6. # * distributed with this work for additional information
  7. # * regarding copyright ownership. The ASF licenses this file
  8. # * to you under the Apache License, Version 2.0 (the
  9. # * "License"); you may not use this file except in compliance
  10. # * with the License. You may obtain a copy of the License at
  11. # *
  12. # * http://www.apache.org/licenses/LICENSE-2.0
  13. # *
  14. # * Unless required by applicable law or agreed to in writing, software
  15. # * distributed under the License is distributed on an "AS IS" BASIS,
  16. # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # * See the License for the specific language governing permissions and
  18. # * limitations under the License.
  19. # */
  20. #
  21. # /* This script takes three arguments,
  22. # * - sshkey: if not specified then ssh w/o key
  23. # * - repository information : to be added to remote node
  24. # * - list of hosts
  25. # */
  26. #set -e
  27. #set -x
  28. trap 'pp_cmd=$ppp_cmd; ppp_cmd=$previous_command; previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
  29. #trap 'echo "$host: retcode:[$?] command:[$previous_command], out:[$out]"' EXIT
  30. #printf 'Argument is __%s__\n' "$@"
  31. master=$1
  32. repo_name=$2
  33. repo_desc=$3
  34. repourl=$4
  35. gpgkeyurl=$5
  36. host=`hostname -f | tr '[:upper:]' '[:lower:]'`
  37. #echo "$host:_ERROR_:$master, $repo_name, $repo_desc, $repourl, $gpgkeyurl"
  38. repo_file_content=''
  39. if [[ -z "$gpgkeyurl" ]]; then
  40. repo_file_content="[$repo_name]\nname=$repo_desc\nbaseurl=$repourl\nenabled=1\ngpgcheck=0"
  41. else
  42. repo_file_content="[$repo_name]\nname=$repo_desc\nbaseurl=$repourl\nenabled=1\ngpgcheck=1\ngpgkey=$gpgkeyurl"
  43. fi
  44. out=`echo -e $repo_file_content > /etc/yum.repos.d/$repo_name.repo`
  45. ret=$?
  46. if [[ "$ret" != "0" ]]; then
  47. echo "$host:_ERROR_:retcode:[$ret], CMD:[$pp_cmd]: OUT:[$out]" >&2
  48. exit 1
  49. fi
  50. if [[ ! -z "$gpgkeyurl" ]]; then
  51. out=`rpm --import $gpgkeyurl`
  52. ret=$?
  53. if [[ "$ret" != "0" ]]; then
  54. echo "$host:_ERROR_:retcode:[$ret], CMD:[$pp_cmd]: OUT:[$out]" >&2
  55. exit 1
  56. fi
  57. fi
  58. out=`rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm 2>&1`
  59. out=`/etc/init.d/iptables stop 1>/dev/null`
  60. out=`yum install -y puppet-2.7.9-2`
  61. ret=$?
  62. if [[ "$ret" != "0" ]]; then
  63. echo "$host:_ERROR_:retcode:[$ret], CMD:[$pp_cmd]: OUT:[$out]" >&2
  64. exit 1
  65. fi
  66. out=`mkdir -p /etc/puppet/agent 2>&1`
  67. agent_auth_conf="path /run\nauth any\nallow $master\n\npath /\nauth any"
  68. out=`echo -e $agent_auth_conf > /etc/puppet/agent/auth.conf`
  69. out=`touch /etc/puppet/agent/namespaceauth.conf`
  70. out=`cp -f /etc/puppet/puppet.conf /etc/puppet/agent/ 2>&1`
  71. ret=$?
  72. if [[ "$ret" != "0" ]]; then
  73. echo "$host:_ERROR_:retcode:[$ret], CMD:[$pp_cmd]: OUT:[$out]" >&2
  74. exit 1
  75. fi
  76. #TODO clean this up for better fix. For now make sure we stop puppet agent. The issue here is we do not know if we started this puppet agent during our run or not.
  77. out=`service puppet stop`
  78. ret=$?
  79. out=`puppet agent --verbose --confdir=/etc/puppet/agent --listen --runinterval 5 --server $master --report --no-client --waitforcert 10 --configtimeout 600 --debug --logdest=/var/log/puppet_agent.log --httplog /var/log/puppet_agent_http.log --autoflush 2>&1`
  80. ret=$?
  81. if [[ "$ret" != "0" ]]; then
  82. echo "$host:_ERROR_:retcode:[$ret], CMD:[$pp_cmd]: OUT:[$out]" >&2
  83. exit 1
  84. fi
  85. exit 0