Class: Bow::InventoryExample

Inherits:
Object
  • Object
show all
Defined in:
lib/bow/inventory_example.rb

Constant Summary collapse

TARGETING_EXAMPLE =
{
  'example_group1' => [
    '192.168.50.27',
    '192.168.50.37'
  ],
  'example_group2' => [
    '192.168.50.47',
    '192.168.50.57'
  ]
}.freeze
RAKEFILE_EXAMPLE =
"  require 'bow/rake'\n\n  Rake.application.options.trace_rules = true\n\n  PROVISION_DIR = '/tmp/rake_provision'\n\n  namespace :example_group1 do\n    task provision: :print_hello do\n    end\n\n    # The task :print_hello from the :example_group1 will run only once\n    flow run: :once\n    task :print_hello do\n      sh 'echo \"Hello from example group #1 server!\"'\n    end\n  end\n\n  namespace :example_group2 do\n    task provision: :print_hello do\n    end\n\n    # The task :pring_hello from the example_group2 will run everytime\n    # until it is disabled.\n    # Change enabled value to \"false\" to run the reverting task (:print_goodbye)\n    flow enabled: true, revert: :print_goodbye\n    task :print_hello do\n      sh 'echo \"Hello from example group #2 server!\"'\n    end\n\n    task :print_goodbye do\n      sh 'echo \"Goodbye! The task at example group #2 is reverted!\"'\n    end\n  end\n".gsub(/^ {6}/, '').freeze

Instance Method Summary collapse

Instance Method Details

#initObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bow/inventory_example.rb', line 53

def init
  raise 'Can not init. Directory not empty!' unless Dir.empty?(Dir.pwd)
  {
    'Rakefile'     => RAKEFILE_EXAMPLE,
    'targets.json' => JSON.pretty_generate(TARGETING_EXAMPLE)
  }.each do |targ, code|
    f = File.open(targ, 'w')
    f.write(code)
    f.close
  end
end