summaryrefslogtreecommitdiffstats
path: root/bin/local_apply.sh
blob: a5f4ac1061fe9b671ae801099a56dbbd35ebaf37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash

# puppetversion >= 4
if [ -f /usr/share/ruby/vendor_ruby/facter/virtual.rb ]; then
  # https://tickets.puppetlabs.com/browse/FACT-1289
  grep -q 'when /virtualbox/i' /usr/share/ruby/vendor_ruby/facter/virtual.rb
  if [ $? -gt 0 ]; then
   pushd /
   rpm -qi patch > /dev/null || puppet resource package patch ensure=installed
   patch -p 0 <<END
--- /usr/share/ruby/vendor_ruby/facter/virtual.rb_old 2015-12-21 17:42:05.909487491 +0100
+++ /usr/share/ruby/vendor_ruby/facter/virtual.rb 2015-12-21 17:40:43.533994750 +0100
@@ -256,6 +256,8 @@
         'xenu'
       when /ibm_systemz/i
         'zlinux'
+      when /virtualbox/i
+        'virtualbox'
       else
         output.to_s.split("\n").last
       end
END
   popd
  fi
fi

set -e

# sofar only for puppet < 4
if [ ! -x /opt/puppetlabs/bin/puppet ] && [ ! -d /var/lib/puppetdb ]; then
  [ -f /etc/yum.repos.d/puppetlabs.repo ] || rpm -Uvh http://yum.puppetlabs.com/el/7/products/x86_64/puppetlabs-release-7-11.noarch.rpm
  # setup puppetdb & other things for local apply
  pre_setup=''
  setup="
exec{'generate_certs':
  command => 'puppet master --masterport 8141; sleep 10; kill \`cat /var/run/puppet/master.pid\`',
  creates => \"/var/lib/puppet/ssl/certs/\${::fqdn}.pem\",
  before  => Package['puppetdb'],
}
class{'puppetdb::globals':
  version => '2.3.8-1.el7'
}
class{'::puppetdb':
  database        => 'embedded',
  manage_dbserver => false,
  manage_firewall => false,
} -> package {'puppetdb-terminus':
  ensure => installed,
} -> file{'/etc/puppet/puppetdb.conf':
  content => \"[main]\nserver = \${::fqdn}\nport = 8081\n\",
  notify  => Service['puppetdb'],
} -> file{'/etc/puppet/routes.yaml':
  content => '---
apply:
  catalog:
    terminus: compiler
    cache: puppetdb
  facts:
    terminus: facter
    cache: puppetdb_apply
',
}
"
else
  pre_setup="
package{'puppet-agent-extensions':
  ensure => installed,
}
"
  setup=''
fi
if [ ! -x /opt/puppetlabs/bin/puppet ]; then
  hiera_conf="--hiera_config=/etc/puppet/ibox/hieradata/config.yaml"
  puppet_args="--parser=future --storeconfigs --storeconfigs_backend=puppetdb --report --reports=puppetdb ${hiera_conf}"
else
  hiera_conf='--hiera_config=/etc/puppet/ibox/hiera.yaml '
  puppet_args="${hiera_conf}"
fi

if [ ! -f /usr/local/bin/motd_gen.sh ]; then
  # we need trocla so that hiera works
  if [ ! -z "${pre_setup}" ]; then
    puppet apply --modulepath=/etc/puppet/ibox/modules/public/:/etc/puppet/ibox/modules/ibox/ <<EOF | tee -a /var/log/ibox.log
  ${pre_setup}
EOF
  fi
  puppet apply ${hiera_conf} --modulepath=/etc/puppet/ibox/modules/public/:/etc/puppet/ibox/modules/ibox/ <<EOF | tee -a /var/log/ibox.log
Exec { path => '/sbin:/usr/bin:/usr/sbin:/bin:/usr/local/bin:/usr/local/sbin', }
${setup}
ensure_packages(['rubygem-base32'])
include ::motd::puppetmaster
class{'::trocla::yaml':
  edit_uid => 'root',
}
include ::trocla::master::hiera
class{'::iuid::config':
  edit_uid => 'root',
}
EOF
fi

puppet apply --show_diff --modulepath=/etc/puppet/ibox/modules/public/:/etc/puppet/ibox/modules/ibox/ ${puppet_args} /etc/puppet/ibox/manifests/ $@ | tee -a /var/log/ibox.log