1

TLDR:

I can't configure ordered chain of Puppet "Exec" commands to run ONLY ONCE.

Details:

I want to use Vagrant and Puppet modules to setup VM with installed Redmine and some sample data loaded into it. I'm using https://forge.puppetlabs.com/johanek/redmine and it works great - Redmine is installed and it works.

My goal:
Now I want to load sample data into Redmine using REST API:

  1. Create 1 test project
  2. Import 2 issues into this project

I want to run 2 simple "Exec", one after another and ONLY ONCE, but I can't achieve this, hence the question.

My current effort:
I've tried to subscribe to one of latest steps in redmine installation

subscribe => [Exec['rails_migrations']]

and then import data, but the first step "create-project1" always notifies second step "import-issues", so it creates duplicated data. And if run vagrant provision few times, the "import-issues" creates duplicates of this issues. Here is my code:

exec {'create-project1':
    subscribe => [Exec['rails_migrations']],
    path    => ['/usr/bin', '/usr/sbin', '/bin'],
    creates => "$redmine_install_dir/.data_loaded",
    command => "curl WHICH_CREATES_PROJECT && touch $redmine_install_dir/.data_loaded",
    notify  => [Exec['import-issues']],
} ->
exec {'import-issues':
    path    => ['/usr/bin', '/usr/sbin', '/bin'],
    command => "curl WHICH_IMPORTS_ISSUES",
    refreshonly => true,
}

Question:
How to configure those Exec commands to run in chain and ONLY ONCE?

Im also thinking about extending this chain to 5 commands in near future, so keep that in mind.

4

1 回答 1

0

'ONLY ONCE' 你几乎在那里 - Puppet 有onlyif属性,你可以在你的 exec 块中包含这些属性来测试文件是否已经存在。

然后你可以做类似的事情

exec {'create-project1':
    subscribe => [Exec['rails_migrations']],
    path    => ['/usr/bin', '/usr/sbin', '/bin'],
    onlyif  => "test ! -f $redmine_install_dir/.data_loaded"
    command => "curl WHICH_CREATES_PROJECT && touch $redmine_install_dir/.data_loaded",
    notify  => [Exec['import-issues']],

哪个测试存在$redmine_install_dir/.data_loaded- 你应该能够玩一点,以实现你想要的

于 2015-10-22T08:29:31.647 回答