class UCMT::Ansible
Constants
- USERS_MAPPING
Public Class Methods
new(output_dir)
click to toggle source
# File lib/ucmt/ansible.rb, line 7 def initialize(output_dir) @output_dir = output_dir end
Public Instance Methods
apply()
click to toggle source
# File lib/ucmt/ansible.rb, line 30 def apply Cheetah.run("ansible-playbook", File.join(@output_dir, "states.yml"), stdout: STDOUT) end
dry_run()
click to toggle source
# File lib/ucmt/ansible.rb, line 26 def dry_run Cheetah.run("ansible-playbook", File.join(@output_dir, "states.yml"), "--check", "--diff", stdout: STDOUT) end
write(data)
click to toggle source
# File lib/ucmt/ansible.rb, line 11 def write(data) FileUtils.mkdir_p(@output_dir) result = local_users_content(data) content = [{ "name" => "UCMT defined tasks", "hosts" => "localhost", "connection" => "local", "tasks" => result }] File.write(File.join(@output_dir, "states.yml"), content.to_yaml) end
Private Instance Methods
local_users_content(data)
click to toggle source
# File lib/ucmt/ansible.rb, line 46 def local_users_content(data) result = [] users_data = data["local_users"] return [] unless users_data (users_data["add"] || []).each do |user| res = { "name" => "User #{user["name"]}" } key2 = "ansible.builtin.user" res[key2] = {} USERS_MAPPING.each_pair do |k, v| res[key2][v] = user[k] if user[k] end result << res end (users_data["remove"] || []).each do |user| res = { "name" => "remove " + user["name"] } key2 = "ansible.builtin.user" res[key2] = { "name" => user["name"], "state" => "absent", "remove" => "yes" } result << res end result end