From f233380a00cb3a47ec2cded62ae272e21c934eb1 Mon Sep 17 00:00:00 2001 From: Toshiyuki Suzumura Date: Sat, 8 Jun 2013 00:03:39 +0900 Subject: [PATCH 1/3] Implement install_chef_client option. --- lib/vagrant-aws/action/run_instance.rb | 13 +++++++++++++ lib/vagrant-aws/action/sync_folders.rb | 8 ++++++++ lib/vagrant-aws/config.rb | 9 +++++++++ locales/en.yml | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/lib/vagrant-aws/action/run_instance.rb b/lib/vagrant-aws/action/run_instance.rb index be72f263..ef6bffeb 100644 --- a/lib/vagrant-aws/action/run_instance.rb +++ b/lib/vagrant-aws/action/run_instance.rb @@ -34,6 +34,7 @@ def call(env) subnet_id = region_config.subnet_id tags = region_config.tags user_data = region_config.user_data + install_chef_client = region_config.install_chef_client # If there is no keypair then warn the user if !keypair @@ -45,6 +46,18 @@ def call(env) env[:ui].warn(I18n.t("vagrant_aws.launch_vpc_warning")) end + # If install_chef_client then set install-script to user_data + if install_chef_client + if user_data + env[:ui].warn(I18n.t("vagrant_aws.user_data_overwrite_warning")) + end + user_data = <<-__INSTALL_CHEF__ +#!/bin/sh +curl -L https://www.opscode.com/chef/install.sh | bash +sed -i -e 's/^\\(Defaults.*requiretty\\)/#\\1/' /etc/sudoers + __INSTALL_CHEF__ + end + # Launch! env[:ui].info(I18n.t("vagrant_aws.launching_instance")) env[:ui].info(" -- Type: #{instance_type}") diff --git a/lib/vagrant-aws/action/sync_folders.rb b/lib/vagrant-aws/action/sync_folders.rb index 6023958e..38f5b9a4 100644 --- a/lib/vagrant-aws/action/sync_folders.rb +++ b/lib/vagrant-aws/action/sync_folders.rb @@ -22,6 +22,14 @@ def call(env) ssh_info = env[:machine].ssh_info + region = env[:machine].provider_config.region + region_config = env[:machine].provider_config.get_region_config(region) + if region_config.install_chef_client + # Wait chef-solo... + env[:ui].info(I18n.t("vagrant_aws.waiting_to_install_chef_client")) + env[:machine].communicate.execute("until sudo ls >/dev/null 2>&1; do sleep 1; done") + end + env[:machine].config.vm.synced_folders.each do |id, data| data = scoped_hash_override(data, :aws) diff --git a/lib/vagrant-aws/config.rb b/lib/vagrant-aws/config.rb index 6199b12a..855c787b 100644 --- a/lib/vagrant-aws/config.rb +++ b/lib/vagrant-aws/config.rb @@ -86,6 +86,11 @@ class Config < Vagrant.plugin("2", :config) # @return [String] attr_accessor :user_data + # Set true if install chef-client with user_data. + # + # @return [Boolean] + attr_accessor :install_chef_client + def initialize(region_specific=false) @access_key_id = UNSET_VALUE @ami = UNSET_VALUE @@ -103,6 +108,7 @@ def initialize(region_specific=false) @tags = {} @user_data = UNSET_VALUE @use_iam_profile = UNSET_VALUE + @install_chef_client = UNSET_VALUE # Internal state (prefix with __ so they aren't automatically # merged) @@ -212,6 +218,9 @@ def finalize! # User Data is nil by default @user_data = nil if @user_data == UNSET_VALUE + # install_chef_client is false by default + @install_chef_client = false if @install_chef_client == UNSET_VALUE + # Compile our region specific configurations only within # NON-REGION-SPECIFIC configurations. if !@__region_specific diff --git a/locales/en.yml b/locales/en.yml index 8a5a0849..410d6e8c 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -31,6 +31,11 @@ en: will_not_destroy: |- The instance '%{name}' will not be destroyed, since the confirmation was declined. + user_data_overwrite_warning: |- + Warning! You have specified `user_data` and `install_chef_client = true`. + `user_data` wiill be overwritten for install chef-client. + waiting_to_install_chef_client: |- + Waiting for chef-client to become ready... config: access_key_id_required: |- From 3f21ba3605014c10e4ab75a9a3e7d48add4256bc Mon Sep 17 00:00:00 2001 From: Toshiyuki Suzumura Date: Mon, 10 Jun 2013 23:35:31 +0900 Subject: [PATCH 2/3] Remove chef-installer, I left only the feature of 'disable sudo-requiretty'. --- lib/vagrant-aws/action/run_instance.rb | 11 +++++------ lib/vagrant-aws/action/sync_folders.rb | 6 +++--- lib/vagrant-aws/config.rb | 10 +++++----- locales/en.yml | 8 ++++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/vagrant-aws/action/run_instance.rb b/lib/vagrant-aws/action/run_instance.rb index ef6bffeb..52e0631a 100644 --- a/lib/vagrant-aws/action/run_instance.rb +++ b/lib/vagrant-aws/action/run_instance.rb @@ -34,7 +34,7 @@ def call(env) subnet_id = region_config.subnet_id tags = region_config.tags user_data = region_config.user_data - install_chef_client = region_config.install_chef_client + disable_sudo_requiretty = region_config.disable_sudo_requiretty # If there is no keypair then warn the user if !keypair @@ -46,16 +46,15 @@ def call(env) env[:ui].warn(I18n.t("vagrant_aws.launch_vpc_warning")) end - # If install_chef_client then set install-script to user_data - if install_chef_client + # If disable_sudo_requiretty then set install-script to user_data + if disable_sudo_requiretty if user_data env[:ui].warn(I18n.t("vagrant_aws.user_data_overwrite_warning")) end - user_data = <<-__INSTALL_CHEF__ + user_data = <<-__DISABLE_SUDO_REQUIRE_TTY__ #!/bin/sh -curl -L https://www.opscode.com/chef/install.sh | bash sed -i -e 's/^\\(Defaults.*requiretty\\)/#\\1/' /etc/sudoers - __INSTALL_CHEF__ + __DISABLE_SUDO_REQUIRE_TTY__ end # Launch! diff --git a/lib/vagrant-aws/action/sync_folders.rb b/lib/vagrant-aws/action/sync_folders.rb index 38f5b9a4..fffed065 100644 --- a/lib/vagrant-aws/action/sync_folders.rb +++ b/lib/vagrant-aws/action/sync_folders.rb @@ -24,9 +24,9 @@ def call(env) region = env[:machine].provider_config.region region_config = env[:machine].provider_config.get_region_config(region) - if region_config.install_chef_client - # Wait chef-solo... - env[:ui].info(I18n.t("vagrant_aws.waiting_to_install_chef_client")) + if region_config.disable_sudo_requiretty + # Wait to disable sudo-requiretty ... + env[:ui].info(I18n.t("vagrant_aws.waiting_to_disable_sudo_requiretty")) env[:machine].communicate.execute("until sudo ls >/dev/null 2>&1; do sleep 1; done") end diff --git a/lib/vagrant-aws/config.rb b/lib/vagrant-aws/config.rb index 855c787b..97a93a72 100644 --- a/lib/vagrant-aws/config.rb +++ b/lib/vagrant-aws/config.rb @@ -86,10 +86,10 @@ class Config < Vagrant.plugin("2", :config) # @return [String] attr_accessor :user_data - # Set true if install chef-client with user_data. + # Set true if disable sudo-requiretty with user_data. # # @return [Boolean] - attr_accessor :install_chef_client + attr_accessor :disable_sudo_requiretty def initialize(region_specific=false) @access_key_id = UNSET_VALUE @@ -108,7 +108,7 @@ def initialize(region_specific=false) @tags = {} @user_data = UNSET_VALUE @use_iam_profile = UNSET_VALUE - @install_chef_client = UNSET_VALUE + @disable_sudo_requiretty = UNSET_VALUE # Internal state (prefix with __ so they aren't automatically # merged) @@ -218,8 +218,8 @@ def finalize! # User Data is nil by default @user_data = nil if @user_data == UNSET_VALUE - # install_chef_client is false by default - @install_chef_client = false if @install_chef_client == UNSET_VALUE + # disable_sudo_requiretty false by default + @disable_sudo_requiretty = false if @disable_sudo_requiretty == UNSET_VALUE # Compile our region specific configurations only within # NON-REGION-SPECIFIC configurations. diff --git a/locales/en.yml b/locales/en.yml index 410d6e8c..10b51cbe 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -32,10 +32,10 @@ en: The instance '%{name}' will not be destroyed, since the confirmation was declined. user_data_overwrite_warning: |- - Warning! You have specified `user_data` and `install_chef_client = true`. - `user_data` wiill be overwritten for install chef-client. - waiting_to_install_chef_client: |- - Waiting for chef-client to become ready... + Warning! You have specified `user_data` and `disable_sudo_requiretty = true`. + `user_data` wiill be overwritten for setting to /etc/sudoers. + waiting_to_disable_requiretty: |- + Waiting for setting to /etc/sudoers... config: access_key_id_required: |- From f27ecc7060ee0d2bff1d3eb79f89ef0a1427cfd9 Mon Sep 17 00:00:00 2001 From: Toshiyuki Suzumura Date: Fri, 14 Jun 2013 20:48:23 +0900 Subject: [PATCH 3/3] Bugfix: I was wrong string for the message. --- locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/en.yml b/locales/en.yml index 10b51cbe..ebb547ef 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -34,7 +34,7 @@ en: user_data_overwrite_warning: |- Warning! You have specified `user_data` and `disable_sudo_requiretty = true`. `user_data` wiill be overwritten for setting to /etc/sudoers. - waiting_to_disable_requiretty: |- + waiting_to_disable_sudo_requiretty: |- Waiting for setting to /etc/sudoers... config: