จะแน่ใจได้อย่างไรว่า puppet exec ทำงานในทุกเหตุการณ์ที่ถูกทริกเกอร์

ฉันต้องการให้ puppet exec ทำงานในการปรับใช้ไฟล์ครั้งแรกและทุกครั้งที่มีการเปลี่ยนแปลงเพิ่มเติมในไฟล์ เพื่อที่ฉันได้สร้างโค้ดด้านล่างใน puppet

Exec ไม่ทำงานในการปรับใช้ไฟล์ครั้งแรก ฉันคิดว่ามันเป็นเพราะการรีเฟรชเท่านั้น ไม่มีใครรู้ว่าต้องเปลี่ยนแปลงอะไรในรหัส?

define dev_tools::javacert(
  $keystore="/etc/alternatives/java_sdk/jre/lib/security/cacerts",
  $storepass='xxx',
  $alias = $name,
  $filecertpath = "/var/lib/certs/${name}.crt",

){
  file{
    $filecertpath:
      source => "puppet:///modules/${module_name}/sonarqube/${::env}/${::server_location}/${filecertpath}",
      mode   => '0644',
      notify => Exec["deploy_javacert_${name}"];
  }
  exec {
    "deploy_javacert_${name}":
       path => "/usr/bin",
       command => "keytool -importcert -keystore ${keystore} -alias $alias -file $filecertpath -storepass ${storepass} -noprompt  2>/dev/null",
       provider => shell,
       refreshonly => true;
  }

}

person devops    schedule 04.04.2019    source แหล่งที่มา
comment
ดังที่ @AlexHarvey กล่าวถึงในคำตอบของเขา รหัสของคุณไม่ตรงกับพฤติกรรมที่คุณกำลังอธิบายและควรทำงานได้ตามต้องการ คุณสามารถจัดเตรียมบันทึกและผลลัพธ์ที่พิสูจน์เป็นอย่างอื่นได้หรือไม่   -  person Matt Schuchard    schedule 04.04.2019
comment
หาก Exec ไม่ทำงานและไม่มีการรายงานข้อผิดพลาด สถานการณ์ที่เป็นไปได้มากที่สุดคือ (1) ไม่มีการใช้ทรัพยากร dev_tools::javacert ในตอนแรก หรือ (2) ไฟล์ที่กำลังจัดการมีอยู่แล้ว โดยมีโหมดและเนื้อหาที่ระบุไว้สำหรับ มัน.   -  person John Bollinger    schedule 05.04.2019


คำตอบ (1)


การใช้รีเฟรชอย่างเดียวดูถูกต้อง ฉันไม่สามารถทำซ้ำสิ่งนี้ได้ การใช้โค้ดเวอร์ชันที่เรียบง่ายนี้:

พยายามสร้าง MCVE:

# test.pp

file { 'foo': 
  path   => '/tmp/foo',
  source => '/tmp/source',
  notify => Exec['bar'],
}
exec { 'bar':
  path        => '/bin',
  command     => 'echo "baz qux"',
  refreshonly => true,
  logoutput   => true,
}

ตั้งค่า:

▶ touch /tmp/source 

การทำงานครั้งแรก:

▶ puppet apply test.pp
...
Notice: /Stage[main]/Main/File[foo]/content: content changed '{md5}0a227d644d5435d49addae1da06e909c' to '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Main/Exec[bar]/returns: baz qux
Notice: /Stage[main]/Main/Exec[bar]: Triggered 'refresh' from 1 event

การทำงานครั้งต่อไป:

▶ puppet apply test.pp
...
Notice: Compiled catalog for 192-168-1-2.tpgi.com.au in environment production in 0.08 seconds
Notice: Applied catalog in 0.03 seconds

เนื้อหาใหม่:

▶ echo foobar > /tmp/source
▶ puppet apply test.pp
...
Notice: /Stage[main]/Main/File[foo]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}14758f1afd44c09b7992073ccf00b43d'
Notice: /Stage[main]/Main/Exec[bar]/returns: baz qux
person Alex Harvey    schedule 04.04.2019
comment
ใช่มันใช้งานได้แล้ว ฉันไม่รู้ว่าทำไมมันไม่ทำงานก่อนหน้านี้ - person devops; 05.04.2019
comment
@devops ดีใจที่มันถูกจัดเรียงอยู่แล้ว - person Alex Harvey; 05.04.2019