i'm trying mount device , later in same chef-client run, need dir.glob('/dev/xvd?') devices, file device mounted doesn't exist until next chef run.
for clarity, mount happen correctly , no errors - can't see device result dir.glob until next chef-client run.
in instance, mount_point = /data , device_id = /dev/xvdf
mount "#{mount_point}" device device_id fstype 'ext4' options 'noatime,nobootwait' action [:enable, :mount] end if try devices , log them out right after utilize mount resource, /dev/xvdf doesn't appear in list.
devices = dir.glob('/dev/xvd?') devices.each |device| log "devices available: #{device}" end my log output appears such. 1 line mount resource , 1 line log output missing new device /dev/xvdf , displays existing device /dev/xvda
- mount /dev/xvdf /data * log[devices available: /dev/xvda] action write ** update ** trying reload ohai available devices.
ohai "reload_filesystem" action :nothing end # can enable , mount , we're done! mount "#{mount_point}" device device_id fstype 'ext4' options 'noatime,nobootwait' action [:enable, :mount] notifies :reload, "ohai[reload_filesystem]", :immediately end log "***** testing ohai reload 1 ****" devices = dir.glob('/dev/xvd?') devcount = devices.count log "devices count: #{devcount}" devices.each |d| log "devices available: #{d}" end ohai "reload2" action :reload end log "***** testing ohai reload 2 ****" devices = dir.glob('/dev/xvd?') devcount = devices.count log "devices count: #{devcount}" devices.each |d| log "devices available: #{d}" end ** output **
xxx.xx.x.xxx * mount[/data] action mount xxx.xx.x.xxx - mount /dev/xvdf /data xxx.xx.x.xxx * ohai[reload_filesystem] action reload/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.5.0/lib/ohai/plugins/solaris2/network.rb:57: warning: initialized constant ethernet_encaps xxx.xx.x.xxx /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.5.0/lib/ohai/plugins/solaris2/network.rb:57: warning: previous definition of ethernet_encaps here xxx.xx.x.xxx xxx.xx.x.xxx - re-run ohai , merge results node attributes xxx.xx.x.xxx * log[***** testing ohai reload 1 ****] action write xxx.xx.x.xxx xxx.xx.x.xxx * log[devices count: 1] action write xxx.xx.x.xxx xxx.xx.x.xxx * log[devices available: /dev/xvda] action write xxx.xx.x.xxx xxx.xx.x.xxx * ohai[reload2] action reload/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.5.0/lib/ohai/plugins/solaris2/network.rb:57: warning: initialized constant ethernet_encaps xxx.xx.x.xxx /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.5.0/lib/ohai/plugins/solaris2/network.rb:57: warning: previous definition of ethernet_encaps here xxx.xx.x.xxx xxx.xx.x.xxx - re-run ohai , merge results node attributes xxx.xx.x.xxx * log[***** testing ohai reload 2 ****] action write xxx.xx.x.xxx xxx.xx.x.xxx * log[devices count: 1] action write xxx.xx.x.xxx xxx.xx.x.xxx * log[devices available: /dev/xvda] action write
you're hit 2 pass run see this named compile vs converge.
chef things in order, first compile recipes build resource collection (compile time), once that's done execute code each resource ensure it's in desired state (converge time).
your dir.glob in recipe, when it's executed (at compile time) mount resource has not been run , nothing mounted.
you can embed existing code ruby_block resource run @ convergence time , after mount if it's later in recipe code.
ruby_block 'list available devices' block devices = dir.glob('/dev/xvd?') devices.each |device| chef::log.info("devices available: #{device}") end end end you can't use directly resources inside ruby_block, that's why used chef::log.info documentation has examples it.
update per comment:
try this:
mount "/data" source "/dev/xvdf" # whatever needs done there. end ohai "reload filsystem" action :reload plugin "filesystem" end ruby_block "list filesystems" block node['filesystem'].each |dev,properties| chef::log.warn("#{dev} mounted on #{properties['mount']}") end end end this time used warn level, you'll see printed, if not try running chef-client -l info
Comments
Post a Comment