Class: ForemanAnsible::PlaybookCreator

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_ansible/playbook_creator.rb

Overview

Service to generate a playbook given roles and a list of hosts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role_names) ⇒ PlaybookCreator

Returns a new instance of PlaybookCreator.



6
7
8
# File 'app/services/foreman_ansible/playbook_creator.rb', line 6

def initialize(role_names)
  @role_names = role_names
end

Instance Attribute Details

#role_namesObject (readonly)

Returns the value of attribute role_names.



4
5
6
# File 'app/services/foreman_ansible/playbook_creator.rb', line 4

def role_names
  @role_names
end

Instance Method Details

#roles_playbookObject



10
11
12
13
# File 'app/services/foreman_ansible/playbook_creator.rb', line 10

def roles_playbook
  playbook = ['hosts' => 'all', 'roles' => role_names]
  playbook.to_yaml
end

#roles_tempfileObject



15
16
17
18
19
20
# File 'app/services/foreman_ansible/playbook_creator.rb', line 15

def roles_tempfile
  tempfile = Tempfile.new("foreman-ansible-#{fqdn}-roles")
  tempfile.write(roles_playbook)
  tempfile.close
  tempfile
end