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.



8
9
10
# File 'app/services/foreman_ansible/playbook_creator.rb', line 8

def initialize(role_names)
  @role_names = role_names
end

Instance Attribute Details

#role_namesObject (readonly)

Returns the value of attribute role_names.



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

def role_names
  @role_names
end

Instance Method Details

#roles_playbookObject



12
13
14
15
# File 'app/services/foreman_ansible/playbook_creator.rb', line 12

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

#roles_tempfileObject



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

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