Hi,
I believe that all you have to do is taking care of the proper resource
dependencies.
If you really want to rely on autorequire for this, you will have to
make the logic more dynamic. This is easier if you target a Puppet
version that has support for autobefore in addition to autorequire.
1. Have the user autorequire all groups if ensure => present
2. Have the user autobefore all groups is ensure => absent
This way, Puppet will make sure to remove all users before managing the
group.
Of course, you can do this more safely by adding the appropriate
require/before parameters in your manifest.
HTH,
Felix
On 02/19/2016 10:43 AM, Thomas Champagne wrote:
Hi,
I try to develop a new module to deploy resources with an API REST.
But I have problems to define relationship between two resources.
I haven't problem to fetch and flush resource individually. This two
resources are fetch with a REST endpoint but I can have the
relationship between resources with only one endpoint. When I want to
delete a resource, I must remove the relationship before removing this
resource. But I can't know its dependencies because it is not returned
by its REST endpoint. They are returned by the endpoint of the other
resource.
It is not easy to describe it so I'm going to explain it with an example.
I have two resources group and user with two REST endpoints (with an
example response) :
http://host/api/group :
|
[{name:'developer'},{name:'user'}]
|
http://host/api/user :
|
[{
name:'bob',
groups:['developer','user']
},{
name:'alex',
groups:['user']
}]
|
So I create two types and two provider to manage them :
|
Puppet::Type.newtype(:group)do
apply_to_device
ensurable
newparam(:name,:namevar =>true)
end
Puppet::Type.newtype(:user)do
apply_to_device
ensurable
newparam(:name,:namevar =>true)
newproperty(:groups,:array_matching =>:all)
autorequire(:group)do
self[:group]
end
end
|
The puppet config is :
|
node 'host'{
user {'bob':
ensure=>present,
groups =>['developer','user'],
}
user {'alex':
ensure=>present,
groups =>['user'],
}
group{'developer',
ensure=>present,
}
group{'user',
ensure=>present,
}
}
|
When I run "puppet device", the log is :
prefetch group
flush group 'developer'
flush group 'user'
prefetch user
flush user 'bob'
flush user 'alex'
Now I want to delete a group :
|
node 'host'{
user {'bob':
ensure=>present,
groups =>['user'],
}
user {'alex':
ensure=>present,
groups =>['user'],
}
group{'developer',
ensure=>absent,
}
group{'user',
ensure=>present,
}
}
|
When I run "puppet device", the log should be :
prefetch group
destroy group 'developer'
prefetch user
flush user 'bob'
But, when I want to delete a group, the endpoint check if is not
affected to a user and throw an exception it there is any
relationship. So, I must remove all user group before remove the group.
But I think this is not possible to do this with puppet because the
management of each resource is by type. Puppet doesn't know the
relations of a group when it flush the data group.
Is it possible with puppet to update the state of resources in this
order :
prefetch group
prefetch user
destroy group 'developer' and relationship with user 'bob'
flush user 'bob'
I try other solution with an autosubscribe instead of autorequire to
have a notification when the group is deleted but this notification
happens at the end :
prefetch group
destroy group 'developer'
flush group 'user'
prefetch user
flush user 'bob'
flush user 'alex'
notify user 'bob'
I think the best order to do this is :
prefetch group
prefetch user
notify user 'bob' => Call an REST endpoint to remove relationship
destroy group 'developer'
flush group 'user'
flush user 'bob'
flush user 'alex'
Cheers,
Thomas
--
You received this message because you are subscribed to the Google
Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to puppet-users+unsubscr...@googlegroups.com
<mailto:puppet-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/df12fe71-070e-4a37-8b6f-e264b9470daf%40googlegroups.com
<https://groups.google.com/d/msgid/puppet-users/df12fe71-070e-4a37-8b6f-e264b9470daf%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Puppet
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/56D1D7A0.2060902%40Alumni.TU-Berlin.de.
For more options, visit https://groups.google.com/d/optout.