 last part should happen in  finally  block to restore file contents even if puppet failed you should restore file contents  not dump new yaml into it  you ll lose all comments and  pretty  formatting  from user pov if safe dump fails for some reason  file will end up empty  use our atomic file updating approach 