Skip to content

Instantly share code, notes, and snippets.

@neidiom
Forked from lusis/chef-rundeck.rb
Created December 10, 2021 13:18
Show Gist options
  • Save neidiom/3f6eff8c35e3a664da7f5b0313c6324e to your computer and use it in GitHub Desktop.
Save neidiom/3f6eff8c35e3a664da7f5b0313c6324e to your computer and use it in GitHub Desktop.
# run with
# chef-apply chef-rundeck.rb
require 'chef'
require 'chef/node'
require 'chef/mixin/xml_escape'
require 'chef/rest'
require 'chef/role'
require 'chef/environment'
require 'chef/data_bag'
require 'chef/data_bag_item'
require 'partial_search'
Chef::Config.from_file('/etc/chef/client.rb')
all_chef_nodes = search(:node, "*:*")
chef_nodes = all_chef_nodes.sort_by { |k| k.name }
template "/var/lib/rundeck/nodes.yaml" do
local true
source "/var/lib/rundeck/nodes.yaml.erb"
owner "rundeck"
group "adm"
variables(:chef_nodes => chef_nodes)
mode "0640"
end
<% @chef_nodes.each do |server| -%>
<%= server.name %>:
hostname: <%= server['ipaddress'] %>
nodename: <%= server.name %>
username: username
environment: <%= server.chef_environment %>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment