Forge Home

wait_for

A pseudo resource type to wait for a condition to become satisfied.

43,820 downloads

97 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 3.0.1 (latest)
  • 3.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.2
  • 2.0.1
  • 2.0.0
released Aug 25th 2024
This version is compatible with:
  • Puppet Enterprise 2023.8.x, 2023.7.x, 2023.6.x, 2023.5.x, 2023.4.x, 2023.3.x, 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x
  • Puppet >= 6.0.0 < 9.0.0
  • , Archlinux, , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'heini-wait_for', '3.0.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add heini-wait_for
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install heini-wait_for --version 3.0.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

heini/wait_for — version 3.0.1 Aug 25th 2024

puppet-wait-for

Build Status

A Puppet resource type that enables you to either wait for certain amount of time or certain conditions, like

  • shell commands to query arbitrary things and either react on the exit code or match the output of the command against a regular expression, or
  • files or directories to (dis-)appear (new in 3.0)

Warning: By using this module you are leaving the purist Puppet philosophy - this is not really a resource whose state can updated/kept in sync by Puppet. Also, you might be tempted to use this module to work around issues that should be fixed by other means.

That said, there are situations where this might come in handy - for example, when you need to start/stop services in some asynchronous fashion. Puppet's basic assumption is, that when the code to update a resource has finished, then the resource is in the desired state, period. In the real world, this is not always the case, especially if you are doing a lot of things via exec resources and even more if the exec command forks or kicks off a process which needs some time to come up.

Installation

Either install the latest release from puppet forge:

puppet module install heini-wait_for

Or add to your Puppetfile:

mod 'heini/wait_for'

Migrating to version 3.x

With the addition of waiting for files/directories, it doesn't make sense anymore for "query" to be the namevar, which means it must from now on be explicitely provided. For example, instead of writing

wait_for { 'command':
  exit_code => 0,
  ...
}

one should now write

wait_for { 'command_returns_0':
  query     => 'command',
  exit_code => 0,
  ...
}

Usage

Simply add this module to your Puppetfile to make the type available.

Examples

Wait for a Linux sshd service to start:

service { 'logstash':
  ensure => running,
  enable => true,
}

# Wait for the service to really start.
wait_for { 'logstash':
  query             => 'cat /var/log/logstash/logstash-plain.log 2> /dev/null',
  regex             => 'Successfully started Logstash API endpoint',
  polling_frequency => 5,  # Wait up to 2 minutes (24 * 5 seconds).
  max_retries       => 24,
  refreshonly       => true,
}

Wait for a Windows MySQL service to start:

wait_for { 'MySQL service running':
  query => 'sc query MySQL5',
  regex => '.*STATE\s*:\s*4\s*RUNNING.*',
}

Wait until a command returns an exit code of 5:

wait_for { 'Copy to remote host':
  query             => 'scp big_file user@remote.com:/tmp',
  exit_code         => 5,   # Handle exit code 5, connection lost.
  polling_frequency => 0.3,
  max_retries       => 5,
}

Just wait for 1 minute:

wait_for { 'a_minute':
  seconds => 60,
}

Execute a command and inject some environment variables (just like 'exec' does).

wait_for { 'FOO is set':
  query       => 'env',
  environment => ['FOO=bar', 'BAR=baz'],
  regex       => 'FOO=.*',
}

Wait for a file/directory to (dis-)appear

wait_for { 'some_new_file':
  path  => '/tmp/foo',
  state => file,   # or present, absent or directory
}

Testing

Testing

Make sure you have:

  • rake
  • bundler
  • Vagrant (for the Beaker tests)

Install the necessary gems:

bundle install

To run the tests from the root of the source code:

bundle exec rake spec

To also run the acceptance tests:

export BEAKER_PUPPET_COLLECTION=puppet7
export BEAKER_PUPPET_INSTALL_VERSION=7.32.1
bundle exec rspec spec/acceptance

Tested using Puppet 7.32.1, 8.8.1 and Ruby 3.1.4.

Release

This module uses Puppet Blacksmith to publish to the Puppet Forge.

Ensure you have these lines in ~/.bash_profile:

export BLACKSMITH_FORGE_URL=https://forgeapi.puppetlabs.com
export BLACKSMITH_FORGE_USERNAME=xxxxx
export BLACKSMITH_FORGE_PASSWORD=xxxxxxxxx

Build the module:

bundle exec rake build

Push to Forge:

bundle exec rake module:push

Clean the pkg dir (otherwise Blacksmith will try to push old copies to Forge next time you run it and it will fail):

bundle exec rake module:clean