toretore has quit [Quit: This computer has gone to sleep]
mehlah has quit [Quit: Leaving...]
charliesome has joined #ruby-lang
gix has quit [Ping timeout: 240 seconds]
gix has joined #ruby-lang
JoshuaPaling has joined #ruby-lang
Jeticus has quit []
rh1n0 has joined #ruby-lang
tunabee has joined #ruby-lang
tunabee has quit [Remote host closed the connection]
robbyoconnor has joined #ruby-lang
bruno- has joined #ruby-lang
robbyoconnor has quit [Remote host closed the connection]
robbyoconnor has joined #ruby-lang
jxie has quit [Write error: Connection reset by peer]
bruno- has quit [Ping timeout: 260 seconds]
jxie has joined #ruby-lang
mykoweb has joined #ruby-lang
centrx has quit [Quit: Mead error: Connection reset by beer]
senoralastair has joined #ruby-lang
robbyoconnor has quit [Remote host closed the connection]
mehlah has joined #ruby-lang
<senoralastair>
hi folks. I had a (hopefully) easy question, that I'm struggling with a bit. I'm using puppet with the ruby templates, and I'm trying to access elements of a hash. I can't quite figure out how to get the info. I have a working ruby statement for an array (I think it's an array), but I can't get a hash one going. Can anyone point out where I'm going wrong? The statement that is ok is: <% hosts.each do |fn| %><%= fn["host"]["name"] %>,<% end %>.
sepp2k1 has quit [Read error: Connection reset by peer]
nathanstitt has quit [Quit: I growing sleepy]
enebo has joined #ruby-lang
Cakey has quit [Read error: Connection reset by peer]
enebo has quit [Client Quit]
karamazov has quit []
<ScroopyNoopers>
senoralastair: that's a hash; it has non-numeric keys
mykoweb has quit [Remote host closed the connection]
mykoweb has joined #ruby-lang
Cakey has joined #ruby-lang
mykoweb has quit [Ping timeout: 255 seconds]
<senoralastair>
ScroopyNoopers: oh right. ok. well I guess i have to translate it then for the other hash. in this example, does the 'fn' resolve to the current key name? or the array name etc?? for does the format fn["host"]["name"] actually do? (ie what's what in that statement)?
mistym has quit [Remote host closed the connection]
charliesome has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<senoralastair>
ScroopyNoopers: if I had the hash come back as "results": {"hostname.domain":{"ipaddress_mgmt":"1.2.2.4"}.... how do I pull out just the 1.2.3.4 value?
charliesome has joined #ruby-lang
<ScroopyNoopers>
fn is the parameter of the each block
<ScroopyNoopers>
and is a hash. fn["host"] is also a hash within it
<ScroopyNoopers>
assuming the hash is called hash, you would do hash["results"]["hostname.domain"]["ipaddress_mgmt"]
D9 has quit [Ping timeout: 264 seconds]
bruno- has joined #ruby-lang
dfranciosi has joined #ruby-lang
<senoralastair>
ScroopyNooper: what does the fn parameter do?
bruno- has quit [Ping timeout: 245 seconds]
dfranciosi has quit [Ping timeout: 256 seconds]
<ScroopyNoopers>
hosts.each do |fn| do … end runs the block on each element of hosts in turn
<ScroopyNoopers>
that's fn
<ScroopyNoopers>
that's just the name it gives the element it's working on
<senoralastair>
ScroopyNooper: the actual array I'm getting with the ip address only has 1 result, with what appears to be {"hostname.domain":{"ipaddress_mgmt":"1.2.2.4"} as the full response (which is what I want). I call the array like this: $ip = foreman(....), so when accessing this, should I still need the .each do loop? or can I name it, seeing that I should know the hostname.domain bit from this previous hash output?
<ScroopyNoopers>
oh... well, if it stays the same every time you can do it without each
<ScroopyNoopers>
also, it occurs to me now it might be JSON; but only if all that "{...: {...: ...}}}" is in a string
<senoralastair>
yeah. i think it's json
<ScroopyNoopers>
oh, well that's a whole other story
<ScroopyNoopers>
I don't use JSON so I won't be of much help, but it shouldn't be hard to parse it
<senoralastair>
ScroopyNooper: this function was written to return just the data, I think. The json bit was coming back is when I did a curl against the api
Atttwww has joined #ruby-lang
<senoralastair>
ScroopyNooper: sorry for the confusion, I decided to work out the api calls to try and get my head around how I access the data within the ruby template
<senoralastair>
ScroopyNooper: so it's just the raw data i'm dealing with
<ScroopyNoopers>
yeah... big apologies here. Ruby hash syntax doesn't allow a key name to have quotes around it, except using the old => syntax
charliesome has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<ScroopyNoopers>
to parse JSON you just need a require 'json' and a call JSON.parse(whatever)
<senoralastair>
ScroopyNooper: Luckily the json part is only in a raw call to the api. The function I'm calling to get the data deals with that. re the quotes around key names, how do I know if it's using the => syntax?
ta has joined #ruby-lang
<senoralastair>
ScroopyNooper: if it's telling me that it 'can't convert String into Integer', does that mean it's returning an array instead?
<Rakko>
The => syntax for hashes looks like { :key_name => value }
cleopatra has quit [Read error: Connection reset by peer]
<Rakko>
it always has that => instead of a colon in that position
tectonic has joined #ruby-lang
karamazov has quit [Remote host closed the connection]
<Rakko>
I would guess that is true, yes.
cmoneylulz has joined #ruby-lang
bruno- has joined #ruby-lang
<senoralastair>
Rakko: Hi. Yeah I can't actually see what's being returned, as this is a function that was written for puppet. I think I've kind of got my head around it. I'll do some f testing and let you guys know if I've completely messed it up! :-)
Cakey has quit [Read error: Connection reset by peer]
* Rakko
was Scroopy before... just changed nicks :)
<Rakko>
I've never used puppet itself, unfortunately
<Rakko>
but that error is consistent with the thing being an array
hahuang65 has joined #ruby-lang
bruno- has quit [Ping timeout: 250 seconds]
creede has joined #ruby-lang
Cakey has joined #ruby-lang
pr0ton has quit [Quit: pr0ton]
hahuang65 has quit [Ping timeout: 260 seconds]
cmoneylulz has quit []
Guest40124 has quit [Remote host closed the connection]
araujo has quit [Quit: Leaving]
spastorino has quit [Quit: Connection closed for inactivity]
rh1n0 has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
CaptainJet has joined #ruby-lang
hahuang65 has joined #ruby-lang
kyb3r_ has joined #ruby-lang
hahuang61 has joined #ruby-lang
hahuang65 has quit [Ping timeout: 256 seconds]
<senoralastair>
Rakko: ah right. thought someone else had come to join in. I noticed that when I did the curl, I am getting colons instead of =>. I only just clicked about your earlier comment about hash containing hashes! So do I do something like xxx[results]["name"]["ipaddress_mgmt"] to pull out an ip of a hash called 'results', containing the first element, which is a hash called name, with the ipaddress_mgmt key?
MindfulMonk has quit [Ping timeout: 256 seconds]
apeiros has quit [Read error: Connection reset by peer]
apeiros has joined #ruby-lang
<senoralastair>
also, how do I include a variable in one of the []s? ($name is being passed to this in a loop).
pr0ton has joined #ruby-lang
relix has joined #ruby-lang
vincent has joined #ruby-lang
vincent is now known as Guest91674
<Rakko>
senoralastair: well xxx is the name of the topmost hash there. but if it has a key "results" you would do xxx["results"], etc.
<Rakko>
you just put the name of the variable, e.g. xxx["results"][$name]
<Rakko>
it will use the value of the variable as the actual key
ledestin has quit [Ping timeout: 245 seconds]
Guest91674 has quit [Ping timeout: 240 seconds]
apeiros has quit [Remote host closed the connection]
ledestin has joined #ruby-lang
apeiros has joined #ruby-lang
creede has quit [Ping timeout: 260 seconds]
creede has joined #ruby-lang
_ht has joined #ruby-lang
hahuang61 has quit [Ping timeout: 260 seconds]
apeiros has quit [Ping timeout: 245 seconds]
<senoralastair>
Rakko: I'm still slightly confused. I've done $ip = function()... (which returns the hash within puppet) , and then calling it within a template bit with this: <% ip.each do|xxx| %><%= xxx[ip][$name][ipaddress_mgmt] %>,<% end %>, i'm just not sure if the [ip] bit here is correct. is it needed? or have I got too many levels? As it is, it's now saying 'Failed to parse inline template: can't convert Hash into Integer'. ??
<Rakko>
hmm
tectonic has quit []
scmx has joined #ruby-lang
<Rakko>
You have two similarly-named things there: $ip and ip. $ip is defined, but ip is most likely not. And as I said before, xxx is really JSON instead of a hash, so you have to parse it into a hash before you can go using [] on it.
bruno- has joined #ruby-lang
<Rakko>
I'm not sure if when you say xxx[ip] you mean that there's an actual key inside it named "ip" -- or if you're referring back to that $ip variable you defined. But I don't see a sensible reason to refer to $ip within the brackets like that, so I'm guessing the former.
Cakey has quit [Read error: Connection reset by peer]
bruno- has quit [Ping timeout: 256 seconds]
MindfulMonk has joined #ruby-lang
<senoralastair>
Rakko: I think I've added an extra [] in to the mix here. 'ip' isn't returned in the hash, it's just the variable name that holds the hash. the (json formatted) is something like {"fqdn":{:ipaddress_mgmt":"1.2.3.4"},"fqdn2":{ipaddress_mgmt":"5.6.7.8"},... (where fqdn is the $name variable I'm trying to match in this array
Cakey has joined #ruby-lang
AKASkip has joined #ruby-lang
<Rakko>
ok
<Rakko>
so require 'json'
<Rakko>
ip_hash = JSON.parse(ip)
<Rakko>
and then what data do you actually want from it? the IP addresses?
diegoviola has quit [Remote host closed the connection]
weems|mac has quit [Quit: weems|mac]
<senoralastair>
Rakko: I found I had an error in the search params, which obviously didn't help. but I'm getting the array back again now. Yes, I'm after the value for the ip address. I might have confused you before - the 'hash' data I've been pasting is from a curl command to the api, which returns as json. The actual function that's called within puppet (I think) deals with the json format and gives me a ruby array (or so I believe). I did a <%= ip.inspec
<Rakko>
oh, ok. yes, I was confused about that
<Rakko>
your line cuts off after <%= ip.inspec
hahuang61 has joined #ruby-lang
<senoralastair>
<%= ip.inspect %> before and it gave me something like {"fqdn"=>{"ipaddress_mgmt"=>"1.2.3.4"}, "fqdn2=>.... is that what it should be looking like?
<senoralastair>
Rakko: I've actually got to run now, but thanks heaps for your help. I'll most likely be back lurking tomorrow if I don't finish working this out in the morning. Cheers! :-)
alexju has quit [Remote host closed the connection]
<Rakko>
ok
<Rakko>
sorry I wasn't more help
mehlah has quit [Quit: Leaving...]
ddv has joined #ruby-lang
AKASkip has quit [Ping timeout: 256 seconds]
dfranciosi has joined #ruby-lang
Rakko has quit [Quit: Bye]
vincent has joined #ruby-lang
tbuehlmann has joined #ruby-lang
vincent is now known as Guest37737
mistym has quit [Remote host closed the connection]
apeiros has joined #ruby-lang
macsplean1 has joined #ruby-lang
macsplean1 has quit [Client Quit]
macsplean1 has joined #ruby-lang
vondruch has joined #ruby-lang
hahuang61 has joined #ruby-lang
solars has joined #ruby-lang
AKASkip has joined #ruby-lang
hahuang61 has quit [Ping timeout: 250 seconds]
Cakey has quit [Ping timeout: 264 seconds]
TrueJet has joined #ruby-lang
CaptainJet has quit [Ping timeout: 256 seconds]
Cakey has joined #ruby-lang
arBmind has quit [Quit: Leaving.]
hahuang61 has joined #ruby-lang
bruno- has joined #ruby-lang
Forgetful_Lion has joined #ruby-lang
alexju has joined #ruby-lang
hgl has joined #ruby-lang
hgl has quit [Changing host]
hgl has joined #ruby-lang
alexju has quit [Remote host closed the connection]
mikecmpbll has joined #ruby-lang
arBmind has joined #ruby-lang
bruno- has quit [Ping timeout: 245 seconds]
dfranciosi has quit [Remote host closed the connection]
Cakey has quit [Ping timeout: 250 seconds]
TrueJet has quit []
hahuang61 has quit [Ping timeout: 256 seconds]
mnngfltg has joined #ruby-lang
elia has joined #ruby-lang
joonty has quit [Quit: WeeChat 0.4.2]
alexju has joined #ruby-lang
joonty has joined #ruby-lang
dc5ala has joined #ruby-lang
robmiller has joined #ruby-lang
robmiller has quit [Client Quit]
gregf_ has joined #ruby-lang
cornerma1 has joined #ruby-lang
lsegal has quit [Quit: Quit: Quit: Quit: Stack Overflow.]
cornerman has quit [Ping timeout: 240 seconds]
arBmind1 has joined #ruby-lang
cleopatra has joined #ruby-lang
hahuang61 has joined #ruby-lang
arBmind has quit [Ping timeout: 255 seconds]
ironhide_604 has joined #ruby-lang
hahuang61 has quit [Ping timeout: 256 seconds]
marr has joined #ruby-lang
Cakey has joined #ruby-lang
bruno- has joined #ruby-lang
hahuang61 has joined #ruby-lang
Guest37737 has quit [Remote host closed the connection]
relix has quit [Read error: Connection reset by peer]
relix has joined #ruby-lang
JoshuaPaling has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bruno- has quit [Ping timeout: 250 seconds]
hahuang61 has quit [Ping timeout: 256 seconds]
dangerousdave has joined #ruby-lang
workmad3 has joined #ruby-lang
danijoo has joined #ruby-lang
kek has joined #ruby-lang
hgl_ has joined #ruby-lang
JoshuaPaling has joined #ruby-lang
hgl__ has joined #ruby-lang
hgl has quit [Ping timeout: 264 seconds]
hgl__ has quit [Remote host closed the connection]
hgl__ has joined #ruby-lang
hgl___ has joined #ruby-lang
hgl_ has quit [Ping timeout: 255 seconds]
wallerdev has quit [Quit: wallerdev]
hahuang61 has joined #ruby-lang
hgl__ has quit [Ping timeout: 250 seconds]
workmad3 has quit [Ping timeout: 245 seconds]
hgl____ has joined #ruby-lang
hgl___ has quit [Ping timeout: 260 seconds]
Cort3z has joined #ruby-lang
vincent has joined #ruby-lang
vincent is now known as Guest20985
shinnya has quit [Ping timeout: 240 seconds]
Guest20985 has quit [Ping timeout: 240 seconds]
hahuang61 has quit [Ping timeout: 272 seconds]
macsplean1 has quit [Quit: Leaving]
Fushi has joined #ruby-lang
hgl____ has quit [Read error: Connection reset by peer]
hgl____ has joined #ruby-lang
Cakey has quit [Ping timeout: 240 seconds]
hgl____ has quit [Client Quit]
skade has joined #ruby-lang
mehlah has joined #ruby-lang
hgl____ has joined #ruby-lang
hgl_____ has joined #ruby-lang
hgl____ has quit [Read error: Connection reset by peer]
hgl______ has joined #ruby-lang
ht_ has joined #ruby-lang
lolmaus has quit [Ping timeout: 250 seconds]
hgl_______ has joined #ruby-lang
hgl_______ has quit [Remote host closed the connection]
hgl______ has quit [Read error: Connection reset by peer]
hgl_______ has joined #ruby-lang
lolmaus has joined #ruby-lang
_ht has quit [Ping timeout: 250 seconds]
hgl_____ has quit [Ping timeout: 250 seconds]
bruno- has joined #ruby-lang
bruno- has quit [Ping timeout: 256 seconds]
kek has quit [Remote host closed the connection]
kek has joined #ruby-lang
Atttwww has quit [Ping timeout: 240 seconds]
alexju has quit [Remote host closed the connection]
hgl_______ has quit [Quit: Computer has gone to sleep.]
Sirupsen has joined #ruby-lang
ht_ has quit [Remote host closed the connection]
Miphix has quit [Quit: Leaving]
certaint1 is now known as certainty
jonathan_alban has joined #ruby-lang
Technodrome has joined #ruby-lang
<Technodrome>
Good day
<jonathan_alban>
Hi all
_ht has joined #ruby-lang
bin7me has joined #ruby-lang
vincent has joined #ruby-lang
vincent is now known as Guest86003
stamina has joined #ruby-lang
sluukkonen1 is now known as sluukkonen
marr has quit [Ping timeout: 256 seconds]
Guest86003 has quit [Ping timeout: 245 seconds]
tkuchiki has joined #ruby-lang
Cort3z has quit [Ping timeout: 260 seconds]
joonty has quit [Ping timeout: 250 seconds]
tkuchiki has quit [Remote host closed the connection]
symm- has quit [Ping timeout: 240 seconds]
godd2 has quit [Ping timeout: 240 seconds]
dc5ala has quit [Ping timeout: 255 seconds]
kyb3r_ has quit [Quit: Leaving]
bruno- has joined #ruby-lang
joonty has joined #ruby-lang
vincent__ has joined #ruby-lang
vincent__ is now known as Guest36060
ironhide_604 has quit [Ping timeout: 240 seconds]
bruno- has quit [Ping timeout: 264 seconds]
spastorino has joined #ruby-lang
Cort3z has joined #ruby-lang
workmad3 has joined #ruby-lang
symm- has joined #ruby-lang
shemerey has joined #ruby-lang
katlogic has quit [Read error: Connection reset by peer]
shinnya has joined #ruby-lang
katlogic has joined #ruby-lang
rh1n0 has joined #ruby-lang
marr has joined #ruby-lang
yfeldblum has quit [Remote host closed the connection]
jxie has quit [Ping timeout: 245 seconds]
jxie has joined #ruby-lang
Technodrome has quit [Quit: Technodrome]
pr0ton has quit [Quit: pr0ton]
stardiviner has joined #ruby-lang
mehlah has quit [Quit: Leaving...]
Sirupsen has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Miphix has joined #ruby-lang
ironhide_604 has joined #ruby-lang
karamazov has joined #ruby-lang
jonathan_alban has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]