Bug #3186
require not working as expected
| Status: | Closed | Start date: | 02/18/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | functions | |||
| Target version: | 0.25.5 | |||
| Affected Puppet version: | 0.25.4 | Branch: | http://github.com/masterzen/puppet/tree/tickets/0.25.x/3186 | |
| Keywords: | require order | |||
| Votes: | 2 |
Description
I have an example where require is not correctly specifying a dependency between classes.
$mysql_old_pw='b' $mysql_root_pw='p' $redmine_db='r' $redmine_db_user='red' $redmine_db_pw='red' include redmine::mysql
class redmine::mysql {
require mysql::server
require mysql::ruby
if ! $redmine_db {
fail('$redmine_db parameter is required')
}
if ! $redmine_db_user {
fail('$redmine_db_user parameter is required')
}
if ! $redmine_db_pw {
fail('$redmine_db_pw parameter is required')
}
database{$redmine_db:
ensure => present,
charset => 'utf8',
provider => 'mysql',
}
database_user{"${redmine_db_user}@localhost":
ensure => present,
password_hash => mysql_password($redmine_db_pw),
require => Database[$redmine_db],
provider => 'mysql',
}
database_grant{"${redmine_db}@localhost/${redmine_db}":
# privileges => [ 'alter_priv', 'insert_priv', 'select_priv', 'update_priv' ],
provider => 'mysql',
privileges => all,
}
}
class mysql::server {
# set the mysql root password
if(! $mysql_root_pw) {
fail('$mysql_root_pw must be set for class mysql::server')
}
package{'mysql-server':
name => 'mysql-server',
ensure => installed,
notify => Service['mysqld'],
}
.....
#more code here
the require statement should order all of the resources in mysql::server before everything in redmine::mysql, but the Database resource is applied before the mysql-server package is installed (see output below).
root@ubuntu:/usr/local/dev/modules/infrastructure/modules/redmine/tests# puppet mysql.pp --noop notice: //mysql::ruby/Package[ruby-mysql]/ensure: is absent, should be present (noop) err: //redmine::mysql/Database[redmine]: Failed to retrieve current state of resource: Provider mysql is not functional on this platform notice: //redmine::mysql/Database_user[redmine@localhost]: Dependency database[redmine] has 1 failures warning: //redmine::mysql/Database_user[redmine@localhost]: Skipping because of failed dependencies notice: //redmine::mysql/Database_grant[redmine@localhost/redmine]: Dependency database[redmine] has 1 failures warning: //redmine::mysql/Database_grant[redmine@localhost/redmine]: Skipping because of failed dependencies notice: //mysql::server/Package[mysql-server]/ensure: is purged, should be present (noop) notice: //mysql::server/Service[mysqld]/enable: is false, should be true (noop) notice: //mysql::server/Service[mysqld]: Would have triggered refresh from 1 dependencies err: //mysql::server/Exec[set_mysql_rootpw]: Failed to retrieve current state of resource: notice: //mysql::server/File[/root/.my.cnf]: Dependency exec[mysqladmin -u root -pblah password password] has 1 failures warning: //mysql::server/File[/root/.my.cnf]: Skipping because of failed dependencies notice: //mysql::server/File[/etc/my.cnf]/ensure: is absent, should be file (noop) notice: //mysql::server/Service[mysqld-restart]: Dependency exec[mysqladmin -u root -pblah password password] has 1 failures warning: //mysql::server/Service[mysqld-restart]: Skipping because of failed dependencies notice: //mysql::server/Service[mysqld-restart]: Would have triggered refresh from 1 dependencies
I can work around by specifying require=>Class[‘mysql::server’] for the resources that care about order, but I would rather use require.
Related issues
History
Updated by James Turnbull over 2 years ago
- Category changed from plumbing to functions
- Status changed from Unreviewed to Accepted
- Assignee set to Brice Figureau
Brice – if you have a chance.
Updated by Brice Figureau over 2 years ago
Dan Bode wrote:
I have an example where require is not correctly specifying a dependency between classes. [snip] I can work around by specifying require=>Class[‘mysql::server’] for the resources that care about order, but I would rather use require.
I think the error is the following:
err: //redmine::mysql/Database[redmine]: Failed to retrieve current state of resource: Provider mysql is not functional on this platform
I’m not familiar with the RAL, but maybe “suitability” is resolved before ordering takes place?
Did you try to individually use “require=>Class[‘mysql::server’]”? If it doesn’t work either, then that’s the root cause.
Updated by Dan Bode over 2 years ago
yes, explicitly adding the require => Class[mysql::server] stuff fixes this issue. (orders things correctly, things work)
Although the resolving stuff looks suspicious its def not the root cause, that error only occurs if mysql has not been installed before the type is used (I have been hacking around with this loading/order stuff). In the same manifest, I found more places where require class isnt creating the dependencies.
also, this is when using the puppet executable (not sure if that should matter), I havent had a change to check it with puppetd.
Updated by Brice Figureau over 2 years ago
Dan Bode wrote:
yes, explicitly adding the require => Class[mysql::server] stuff fixes this issue. (orders things correctly, things work)
Although the resolving stuff looks suspicious its def not the root cause, that error only occurs if mysql has not been installed before the type is used (I have been hacking around with this loading/order stuff). In the same manifest, I found more places where require class isnt creating the dependencies.
also, this is when using the puppet executable (not sure if that should matter), I havent had a change to check it with puppetd.
would you have a simpler manifest exhibiting the problem (ie one not dependent of a type/provider I don’t have access to)?
Updated by Brice Figureau over 2 years ago
Dan Bode wrote:
yes, explicitly adding the require => Class[mysql::server] stuff fixes this issue. (orders things correctly, things work)
Although the resolving stuff looks suspicious its def not the root cause, that error only occurs if mysql has not been installed before the type is used (I have been hacking around with this loading/order stuff). In the same manifest, I found more places where require class isnt creating the dependencies.
also, this is when using the puppet executable (not sure if that should matter), I havent had a change to check it with puppetd.
It would be interesting to use —graph and have a look to the resulting graph to see if there is indeed a relationship.
Updated by Alan Harder about 2 years ago
I believe I have narrowed this to a small test case:
class foo {
require bar, baz
notify { 'foo': }
}
class bar {
notify { 'bar': }
}
class baz {
notify { 'baz': }
}
node default {
include foo
}
The problem seems to be using require for more than one class.. it will include all the classes, but only the last one actually becomes a dependency. In the debug output I see “//foo/require: requires Class[baz]” but no line for Class[bar]. Since the recipe code in the issue description above uses require for more than one class, I think this may be the source of the issue.
Updated by Brice Figureau about 2 years ago
Alan Harder wrote:
I believe I have narrowed this to a small test case: […]
The problem seems to be using require for more than one class.. it will include all the classes, but only the last one actually becomes a dependency. In the debug output I see “//foo/require: requires Class[baz]” but no line for Class[bar]. Since the recipe code in the issue description above uses require for more than one class, I think this may be the source of the issue.
Thanks Alan, I think you found the exact problem. I’ll try to come with a fix during the week-end.
Updated by Brice Figureau about 2 years ago
- Status changed from Accepted to In Topic Branch Pending Review
- Branch set to http://github.com/masterzen/puppet/tree/tickets/0.25.x/3186
Patch pending review in puppet-dev.
The patch is available in my github repository in the tickets/0.25.x/3186 branch: http://github.com/masterzen/puppet/tree/tickets/0.25.x/3186
Updated by Markus Roberts about 2 years ago
- Status changed from In Topic Branch Pending Review to Merged - Pending Release
Updated by Alan Harder about 2 years ago
Fix looks good to me. I applied just the one line change to 0.25.4 and I see resources in the right order with both: require bar, baz or require bar require baz I also see mention of both class dependencies in the —debug output.
Updated by Markus Roberts about 2 years ago
- Status changed from Merged - Pending Release to Ready For Checkin
- Target version set to 0.25.5
This has been applied in master for Rowlf and needs to go in 0.25.x for 0.25.5.
commit:73c8d0d4701f10995c81633b912bc6dc65a2cf78 Fix #3186 – require function set relationship only on the last class
Updated by James Turnbull about 2 years ago
- Status changed from Ready For Checkin to Closed
Pushed in commit:751df45547162632c41cf98a1b1daabbadb1b901 in branch 0.25.x