0

我编写了一个自定义事实来在 Windows 中创建当前日期和时间。当我通知它时,该事实返回当前日期和时间。

例如:

  notify{"test time":
       message=>"$::windows_time",
         }

上述代码的输出是'05-04-2016-194645'

但是当我尝试使用自定义事实创建文件夹时,我无法创建带有时间戳的文件夹。我的代码如下。

    exec{"current date time folder":
    cwd=>"${prodequ_backup_loc}",
    command=>'C:\Windows\System32\cmd.exe /c "md $::windows_time"',
         }

上面的代码使用“${windows_time}”创建了一个文件夹名称。

我创建日期和时间戳的事实如下:

    require 'facter'
          #
          ##Default for non-Linux nodes
          Facter.add(:windows_time) do
          setcode do
           Facter::Util::Resolution.exec('C:\\Windows\\System32\\cmd.exe /c "C:\\time1.bat"')
          end
          end
          #For Linux Nodes
           Facter.add(:windows_time) do
           confine :kernel  => :linux
           setcode do
           nil
           end
           end

任何帮助深表感谢。

4

1 回答 1

0

参考

代码:

file {"c:\\full\\path\\to\\${::windows_time}":
  ensure => directory,
}
于 2016-04-06T22:42:16.533 回答