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
どんな助けでも大歓迎です。