From f900fadd5300316320b4968b66bf2a59e77ff8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 2 May 2013 13:23:23 +0300 Subject: [PATCH 1/2] add pld knife bootstrap script, based on ubuntu10.04-apt.erb --- lib/chef/knife/bootstrap/pld.erb | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/chef/knife/bootstrap/pld.erb diff --git a/lib/chef/knife/bootstrap/pld.erb b/lib/chef/knife/bootstrap/pld.erb new file mode 100644 index 0000000..fb09899 --- /dev/null +++ b/lib/chef/knife/bootstrap/pld.erb @@ -0,0 +1,48 @@ +bash -c ' +<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> + +if [ ! -f /usr/bin/chef-client ]; then + poldek --up --noask -u chef +fi + +awk NF > /etc/chef/validation.pem <<'EOP' +<%= validation_key %> +EOP +chmod 0600 /etc/chef/validation.pem + +<% if @chef_config[:encrypted_data_bag_secret] -%> +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' +<%= encrypted_data_bag_secret %> +EOP +chmod 0600 /etc/chef/encrypted_data_bag_secret +<% end -%> + +<%# Generate Ohai Hints -%> +<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> +mkdir -p /etc/chef/ohai/hints + +<% @chef_config[:knife][:hints].each do |name, hash| -%> +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' +<%= hash.to_json %> +EOP +<% end -%> +<% end -%> + +<% unless @chef_config[:validation_client_name] == "chef-validator" -%> +[ `grep -qx "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" /etc/chef/client.rb` ] || echo "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" >> /etc/chef/client.rb +<% end -%> + +<% if @config[:chef_node_name] %> +[ `grep -qx "node_name \"<%= @config[:chef_node_name] %>\"" /etc/chef/client.rb` ] || echo "node_name \"<%= @config[:chef_node_name] %>\"" >> /etc/chef/client.rb +<% end -%> + +<% if knife_config[:bootstrap_proxy] %> +echo 'http_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb +echo 'https_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb +<% end -%> + +cat > /etc/chef/first-boot.json <<'EOP' +<%= first_boot.to_json %> +EOP + +<%= start_chef %>' -- 1.8.1.6 From ec04901ef1de7c3ee20492d63da4ebbade367df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 25 Jun 2013 09:43:24 +0300 Subject: [PATCH 2/2] create chef client as a whole if file is missing --- lib/chef/knife/bootstrap/pld.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/bootstrap/pld.erb b/lib/chef/knife/bootstrap/pld.erb index fb09899..741a94c 100644 --- a/lib/chef/knife/bootstrap/pld.erb +++ b/lib/chef/knife/bootstrap/pld.erb @@ -1,4 +1,4 @@ -bash -c ' +sh -c ' <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> if [ ! -f /usr/bin/chef-client ]; then @@ -28,6 +28,14 @@ EOP <% end -%> <% end -%> +# create client if none present +if [ ! -e /etc/chef/client.rb ]; then +cat > /etc/chef/client.rb <<'EOP' +<%= config_content %> +EOP +fi + +# update existing config <% unless @chef_config[:validation_client_name] == "chef-validator" -%> [ `grep -qx "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" /etc/chef/client.rb` ] || echo "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" >> /etc/chef/client.rb <% end -%> -- 1.8.1.6