From: Ismaƫl Bouya Date: Sat, 3 Mar 2018 21:24:19 +0000 (+0100) Subject: Fetch node informations from LDAP X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPuppet.git;a=commitdiff_plain;h=85abd2fdbad83430df4824843764719064afb9b4 Fetch node informations from LDAP environment, hostname --- diff --git a/bin/install_script.sh b/bin/install_script.sh index 49a737f..6b1aa39 100755 --- a/bin/install_script.sh +++ b/bin/install_script.sh @@ -12,6 +12,7 @@ cat < $ARCH_INSTALL_SCRIPT < $ARCH_PUPPET_CONFIGURATION_SCRIPT < $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT < "$base_installation::system_hostname\n", - } + if empty($base_installation::system_hostname) { + $hostname = $base_installation::real_hostname + } else { + $hostname = $base_installation::system_hostname + } - exec { "set_hostname": - command => "/usr/bin/hostnamectl set-hostname $base_installation::system_hostname", - refreshonly => true, - subscribe => File["/etc/hostname"], - returns => [0, 1], - } + file { '/etc/hostname': + content => "$base_installation::system_hostname\n", + } - # TODO: find a way to ensure that /etc/hostname doesn't change - # exec { "set_hostname_firstboot": - # command => "/usr/bin/systemd-firstboot --hostname=$base_installation::system_hostname", - # creates => "/etc/hostname", - # } + exec { "set_hostname": + command => "/usr/bin/hostnamectl set-hostname $base_installation::system_hostname", + refreshonly => true, + subscribe => File["/etc/hostname"], + returns => [0, 1], } + # TODO: find a way to ensure that /etc/hostname doesn't change + # exec { "set_hostname_firstboot": + # command => "/usr/bin/systemd-firstboot --hostname=$base_installation::system_hostname", + # creates => "/etc/hostname", + # } + } diff --git a/modules/base_installation/templates/puppet/host_ldap.info.erb b/modules/base_installation/templates/puppet/host_ldap.info.erb index 525739b..a71c6f3 100644 --- a/modules/base_installation/templates/puppet/host_ldap.info.erb +++ b/modules/base_installation/templates/puppet/host_ldap.info.erb @@ -2,7 +2,6 @@ ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF' dn: <%= @ldap_dn %> cn: <%= @ldap_cn %> -cn: <%= @system_hostname %> objectclass: device objectclass: top objectclass: simpleSecurityObject @@ -12,6 +11,7 @@ objectclass: ipHost <% unless @ips["v4"].nil? -%>ipHostNumber: <%= @ips["v4"]["ipAddress"] %><%- end %> <% unless @ips["v6"].nil? -%>ipHostNumber: <%= @ips["v6"]["ipAddress"] %>/<%= @ips["v6"]["mask"] %><%- end %> <%- end -%> +environment: <%= @environment %> userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> EOF #### Or modify an existing entry: @@ -20,6 +20,8 @@ dn: <%= @ldap_dn %> changetype: modify replace: userPassword userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> +replace: environment +environment: <%= @environment %> <%- unless @ips.empty? -%> - delete: ipHostNumber diff --git a/modules/base_installation/templates/puppet/puppet.conf.erb b/modules/base_installation/templates/puppet/puppet.conf.erb index 3748039..24e67c8 100644 --- a/modules/base_installation/templates/puppet/puppet.conf.erb +++ b/modules/base_installation/templates/puppet/puppet.conf.erb @@ -1,8 +1,10 @@ [main] ssldir = <%= @puppet_ssl_path %> +environment = <%= @environment %> + node_terminus = ldap -certname = <%= @system_hostname %> +certname = <%= @real_hostname %> ldapserver = <%= @ldap_server %> ldaptls = true ldapbase = <%= @ldap_base %> diff --git a/modules/profile/manifests/apache.pp b/modules/profile/manifests/apache.pp index 605b701..8db58da 100644 --- a/modules/profile/manifests/apache.pp +++ b/modules/profile/manifests/apache.pp @@ -49,11 +49,17 @@ class profile::apache { ] } + exec { 'Start-apache': + command => "/usr/bin/systemctl start httpd", + before => Class["::letsencrypt"], + unless => "/usr/bin/systemctl is-active httpd", + } + $letsencrypt_certonly_default = { plugin => "webroot", webroot_paths => ["/srv/http/"], notify => Class['Apache::Service'], - require => [Apache::Vhost["redirect_no_ssl"],Apache::Custom_config["letsencrypt.conf"]], + require => [Exec['Start-apache'],Apache::Vhost["redirect_no_ssl"],Apache::Custom_config["letsencrypt.conf"]], manage_cron => true, } diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 32b6ac7..1e39479 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -26,7 +26,7 @@ class role::cryptoportfolio { $cf_group = "cryptoportfolio" $cf_home = "/opt/cryptoportfolio" $cf_env = "prod" - $cf_front_app_host = "cryptoportfolio.immae.eu" + $cf_front_app_host = lookup("base_installation::system_hostname") |$key| { "example.com" } $cf_front_app_port = "" $cf_front_app_ssl = "true" $cf_front_app = "${cf_home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front" diff --git a/python/list_servers.py b/python/list_servers.py new file mode 100644 index 0000000..9b8bc64 --- /dev/null +++ b/python/list_servers.py @@ -0,0 +1,12 @@ +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh + +client = ovh.Client() + +vps_list = client.get('/vps/') + +for vps in vps_list: + print(vps)