]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Make use of LDAP variables to configure node
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 10 Sep 2017 10:45:41 +0000 (12:45 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 10 Sep 2017 19:39:23 +0000 (21:39 +0200)
bin/install_script.sh
environments/production/data/nodes/vps443660.novalocal.yaml [new file with mode: 0644]
environments/production/data/types/vps-ovhssd-1.yaml
environments/production/hiera.yaml
modules/base_installation/manifests/cronie.pp
modules/base_installation/templates/puppet/host_ldap.info.erb
modules/base_installation/templates/puppet/puppet.conf.erb

index f250285840785abeb0025d4e32778cc5f94f208c..f46ab29618e1421ca8d20f1da11e59caf1ed7fb2 100755 (executable)
@@ -20,9 +20,12 @@ ARCH_DIR=`mktemp -d`
 ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
 ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh"
 ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
+ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
+ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
 
 trap "rm -rf $ARCH_DIR" EXIT
 
+#### Base installation stage
 cat > $ARCH_HOST_SCRIPT <<EOF
 #!/bin/bash
 
@@ -117,6 +120,39 @@ send "$password\r"
 expect eof
 EOF
 
+### Role specific stage
+read -p "Press key when LDAP is configured" i
+
+cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
+CODE_PATH="/etc/puppetlabs/code"
+puppet apply --test \$CODE_PATH/manifests/site.pp
+EOF
+
+cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
+DEVICE_STR=\$(cat /proc/mounts | grep "/dev/sd.. /mnt/")
+DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
+MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
+
+cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
+
+/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
+EOF
+
+chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
+
+expect -f - <<EOF
+set timeout -1
+spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT root@$vps_name:/tmp
+expect "assword:"
+send "$password\n"
+expect eof
+spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no root@$vps_name /tmp/arch_host_puppet_configuration_script.sh
+expect "assword:"
+send "$password\r"
+expect eof
+EOF
+
+### Installation finished
 read -p "Reboot to normal? [Y/n]" reboot
 if [ "x$reboot" != "xn" ]; then
   echo "Rebooting"
diff --git a/environments/production/data/nodes/vps443660.novalocal.yaml b/environments/production/data/nodes/vps443660.novalocal.yaml
new file mode 100644 (file)
index 0000000..e6d3c1c
--- /dev/null
@@ -0,0 +1 @@
+base_installation::system_hostname: foo.immae.eu
index 217dd82fc2c7a2109abbb3074a6cae77fdcd6996..968bf6bb17e0fea58d55ee4a790eed41a588839b 100644 (file)
@@ -5,4 +5,3 @@ classes:
 
 base_installation::grub_device: "/dev/sdb"
 base_installation::ldap_cert_path: "/etc/ssl/certs/ca-certificates.crt"
-base_installation::system_hostname: "new.immae.eu"
index f5e5bc22105400b09bbbbec7d2e59e0a99960cee..44c7ecdb060fa55532464ec1cd98ca3edbcd16fe 100644 (file)
@@ -6,8 +6,14 @@ defaults:
   data_hash: yaml_data
 
 hierarchy:
+# FIXME: those informations should be taken in LDAP, but bootstrap
+# problem for the hostname
+  - name: "Per-named-node data"
+    mapped_paths: [ldapvar.self.cn, hostname, "named_nodes/%{hostname}.yaml"]
+
   - name: "Per-node data"
     path: "nodes/%{facts.ec2_metadata.hostname}.yaml"
+### /FIXME
 
   - name: "Per-role data"
     mapped_paths: [ldapvar.self.vars.roles, role, "roles/%{role}.yaml"]
index bcdd9a75f3661b31bd6fdc295934f77b72fd9563..918bce3373af309300c3d62de427fa929a97e33b 100644 (file)
@@ -10,12 +10,18 @@ class base_installation::cronie inherits base_installation {
       owner   => root,
       group   => root,
     }
-    cron { 'puppet-apply':
+    cron { 'puppet-pull-apply':
       ensure  => present,
       command => "cd $base_installation::puppet_code_path ; /usr/bin/git pull",
       user    => root,
       minute  => '*/30',
       require => File['post-hook'],
     }
+    cron { 'puppet-apply':
+      ensure  => present,
+      command => "cd $base_installation::puppet_code_path ; puppet apply --test $base_installation::puppet_code_path/manifests/site.pp",
+      user    => root,
+      minute  => '*/20'
+    }
   }
 }
index a350c37f87f811106dfd7689516a46c81a88ca79..f742da78a23376d97f0ac75bc419d325027c6d91 100644 (file)
@@ -2,6 +2,7 @@
 ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
 dn: <%= @ldap_dn %>
 cn: <%= @ldap_cn %>
+cn: <%= @system_hostname %>
 objectclass: device
 objectclass: top
 objectclass: simpleSecurityObject
index 99d9fc327117442989db50edacfde1ea647325d4..3748039e7e3c4879e672a9aba9f9c5ccf045a3ba 100644 (file)
@@ -2,6 +2,7 @@
 ssldir = <%= @puppet_ssl_path %>
 
 node_terminus = ldap
+certname = <%= @system_hostname %>
 ldapserver = <%= @ldap_server %>
 ldaptls = true
 ldapbase = <%= @ldap_base %>