0
我有下面的配方用於創建一些用戶,將它們添加到組並將密碼設置爲在第一次登錄時過期。如何有條件地在廚師中運行一塊資源或配方?
search(:users, '*:*').each do |user|
userPassword = "$1$scmdevop$ZDTyqia9RXSrpHGK75FjN/"
user user['id'] do
comment user['comment']
home user['home']
shell user['shell']
manage_home true
password "#{userPassword}"
end
if user['sudo'] then
group "#{node.default["sudogroup"]}" do
action :modify
members user['id']
append true
end
end
if (user['resetPassword'] == nil) || (user['resetPassword']) then
bash 'setExporation' do
code 'chage -d 0 ' + user['id']
user 'root'
end
end
end
的問題是,這樣它會繼續重置密碼,並在每次運行設置espiration所以我試圖找到如何使它有條件。我想,如果用戶存在
grep -qs #{user["id"]} /etc/passwd
的問題是,我可以使用not_if子句只在第一個資源,因爲在此之後,用戶已經明確創建使用下面的命令檢查。有沒有辦法讓整個三個資源塊有條件的退出shell代碼?
謝謝, 米歇爾。
如果存在if_not子句,通知是否也會觸發? – Mikyjpeg
我可以使用if子句,問題是我需要從bash命令中設置一些東西(屬性,屬性或環境變量)才能在調用以下資源之前進行檢查。其實唯一的問題是第三個資源,到期日期,至於用戶我可以使用警衛隊和組更改是可以重置爲初始情況。也許我應該爲該特定行爲編寫自定義資源? – Mikyjpeg
我認爲您將使用Ruby語法的if語句混淆了chef資源的'not_if' /'only_if'保護塊/字符串功能。 – coderanger