File: README.md

package info (click to toggle)
puppet-module-heini-wait-for 2.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 136 kB
  • sloc: ruby: 360; sh: 10; makefile: 4
file content (140 lines) | stat: -rw-r--r-- 3,272 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# puppet-wait-for

A Puppet resource type that enables you to wait for certain conditions. You can use shell commands to query arbitrary things and either react on the exit code or match the output of the command against a regular expression.

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 commandforks or kicks off a process which needs some time to come up.

## Installation

Either install the latest release from puppet forge:

~~~ text
puppet module install heini-wait_for
~~~

Or add to your Puppetfile:

~~~ text
mod 'heini/wait_for'
~~~

## Usage

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

## Examples

Wait for a Linux sshd service to start:

~~~ puppet
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:

~~~ puppet
wait_for { 'sc query MySQL5':
  regex => '.*STATE\s*:\s*4\s*RUNNING.*',
}
~~~

Wait until a command returns an exit code of 5:

~~~ puppet
wait_for { '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:

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

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

~~~ puppet
wait_for { 'env':
  environment => ['FOO=bar', 'BAR=baz'],
  regex       => 'FOO=.*',
}
~~~

Use the query namevar:

~~~ puppet
wait_for { 'without implicit namevar':
  query => 'echo foobar',
  regex => 'foobar',
}
~~~

## Testing

### Testing

Make sure you have:

* rake
* bundler

Install the necessary gems:

~~~ text
bundle install
~~~

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

~~~ text
bundle exec rake spec
~~~

### Release

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

Ensure you have these lines in `~/.bash_profile`:

~~~ text
export BLACKSMITH_FORGE_URL=https://forgeapi.puppetlabs.com
export BLACKSMITH_FORGE_USERNAME=heini
export BLACKSMITH_FORGE_PASSWORD=xxxxxxxxx
~~~

Build the module:

~~~ text
bundle exec rake build
~~~

Push to Forge:

~~~ text
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):

~~~ text
bundle exec rake module:clean
~~~