Class: Fhcap::Tasks::Chef::Environments::PromoteCookbooks
- Inherits:
-
ChefTaskBase
- Object
- TaskBase
- ChefTaskBase
- Fhcap::Tasks::Chef::Environments::PromoteCookbooks
- Defined in:
- lib/fhcap/tasks/chef/environments/promote_cookbooks.rb
Instance Attribute Summary collapse
-
#cookbooks ⇒ Object
readonly
Returns the value of attribute cookbooks.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
Attributes inherited from TaskBase
#config, #options, #thor, #verbose
Instance Method Summary collapse
-
#initialize(options) ⇒ PromoteCookbooks
constructor
A new instance of PromoteCookbooks.
- #run ⇒ Object
Methods inherited from ChefTaskBase
#knife_config_dir, #knife_config_file_for, #run_chef_client_cmd, #run_knife_cmd, #run_knife_ssh_cmd
Methods inherited from TaskBase
#ask_config, #color_pad, #exit_with_error, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress
Methods included from KnifeHelper
#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #delete_chef_object, #knife_config, #knife_config_dir, #knife_config_file_for, #knife_data_bag_delete, #knife_download, #knife_environment_delete, #knife_upload, #local_chef_server?, #with_chef_server, #with_local_chef_server
Methods included from ProvidersHelper
#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config
Methods included from ReposHelper
#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_dirty_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #git_diff, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir
Methods included from FhcapHelper
Constructor Details
#initialize(options) ⇒ PromoteCookbooks
Returns a new instance of PromoteCookbooks.
11 12 13 14 15 |
# File 'lib/fhcap/tasks/chef/environments/promote_cookbooks.rb', line 11 def initialize() super @environments = [:environments] || [] @cookbooks = [:cookbooks] || [] end |
Instance Attribute Details
#cookbooks ⇒ Object (readonly)
Returns the value of attribute cookbooks.
9 10 11 |
# File 'lib/fhcap/tasks/chef/environments/promote_cookbooks.rb', line 9 def cookbooks @cookbooks end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
9 10 11 |
# File 'lib/fhcap/tasks/chef/environments/promote_cookbooks.rb', line 9 def environments @environments end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/fhcap/tasks/chef/environments/promote_cookbooks.rb', line 17 def run cookbooks = get_cookbooks() thor.say "Chef::Environments::PromoteCookbooks: environments = #{environments}", :yellow if environments.empty? exit_with_error("You must specify at least one environment during promote!") else repo_cookbook_versions = get_cookbook_versions() do |cookbook, version| thor.say("Adding version constraint #{cookbook} = #{version}") if verbose end environments.each do |environment| environment_filepath = find_environment(environment) if environment_filepath environment_data = JSON.parse(IO.read(environment_filepath)) env_cookbook_versions = environment_data['cookbook_versions'] || {} cookbooks.each do |cookbook| env_cookbook_versions[cookbook] = "= #{repo_cookbook_versions[cookbook]}" end thor.create_file(environment_filepath, JSON.pretty_generate(environment_data), :force => true) else thor.say "Unknown environment #{environment}", :red end end end end |