Class: KnifeSharp::SharpAlign

Inherits:
Chef::Knife
  • Object
show all
Includes:
Common
Defined in:
lib/chef/knife/sharp-align.rb

Instance Method Summary collapse

Methods included from Common

included

Instance Method Details

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/chef/knife/sharp-align.rb', line 46

def run
  # Checking args
  ensure_branch_and_environment_provided!

  # Checking repo branch
  ensure_correct_branch_provided!

  # check cli flags
  if config[:cookbooks] or config[:databags] or config[:roles] or config[:environments]
    do_cookbooks, do_databags, do_roles, do_environments = config[:cookbooks], config[:databags], config[:roles], config[:environments]
  else
    do_cookbooks, do_databags, do_roles, do_environments = true, true, true, true
  end

  ui.msg(ui.color("On server #{chef_server}", :bold)) if chef_server

  SharpCookbookAlign.load_deps
  sca = SharpCookbookAlign.new
  cookbooks_to_update = do_cookbooks ? sca.check_cookbooks(environment) : []
  SharpDataBagAlign.load_deps
  sda = SharpDataBagAlign.new
  databags_to_update = do_databags ? sda.check_databags : {}
  SharpRoleAlign.load_deps
  sra = SharpRoleAlign.new
  roles_to_update = do_roles ? sra.check_roles : {}
  SharpEnvironmentAlign.load_deps
  sea = SharpEnvironmentAlign.new
  environments_to_update = do_environments ? sea.check_environments : {}

  # All questions asked, can we proceed ?
  if cookbooks_to_update.empty? and databags_to_update.empty? and roles_to_update.empty? and environments_to_update.empty?
    ui.msg "Nothing else to do"
    exit 0
  end

  ui.confirm(ui.color("> Proceed ", :bold))
  sca.bump_cookbooks(environment, cookbooks_to_update) if do_cookbooks
  sda.update_databags(databags_to_update) if do_databags
  sra.update_roles(roles_to_update) if do_roles
  sea.update_environments(environments_to_update) if do_environments
end