ruby - List of servers concatenated with domain name into one variable -
i'm looking, if possible, list of servers file , concatenate server names along domain name. possible take list , put 1 variable?
here got , trying make variable or variables:
servers = yaml.load_file "/etc/servers/servers.yml" clients = servers["client_servers"] domain=`hostanme -d` clients.each |d| cservers = [ d, domain ].join('.') end
not sure how .each
, join domain name in 1 line.
i believe you're trying add subdomains domain, correct? if have hostname example.com
, , list of subdomains, can join them so:
hostname = 'example.com' servers = ['www', 'staging', 'm'] full_hosts = servers.map{|server| [server, hostname].join(.)} #=> ['www.example.com', 'staging.example.com', 'm.example.com']
the map
method takes list, processes each item, , gives new list results. i've written more here:
Comments
Post a Comment