Andriy Yurchuk
2013-Feb-04 11:58 UTC
[Puppet Users] Puppet custom recursive directory synchronization
I''m trying to implement a custom recursive directory synchronization resource in Puppet. What I need to do is the following. I have a YAML file with the list of hostnames and the list of directories that should exist on each hostname inside, say, `/var/lib/my_app` directory (`deployment.yml`): host_1: - DIR_1 - DIR_5 host_5: - DIR_7 host_6: - DIR_2 - DIR_3 - DIR_9 On the master I have a directory that contains all of those `DIR_*` sub-directories. Each subdirectory contains some files. What I''m trying to achieve is to synchronize all the nodes according to the `deployment.yml`, so that `/var/lib/my_app` on `host_1` only contains `DIR_1` and `DIR_5`, but does not contain `DIR_7`, `DIR_2`, `DIR_3`, `DIR_9`, and so on. I tried to do this using the ignore variable for file type, but this does not remove the directories from the node if I remove them from deployment.yml. I tried to write a custom function to remove them afterwards, but it does not seem to work inside my manifest. I also wanted to implement a custom type, but it seems to be too complicated. I''d appreciate any help on this. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
刘长元
2013-Feb-04 12:57 UTC
[Puppet Users] Re: Puppet custom recursive directory synchronization
"but this does not remove the directories from the node if I remove them from deployment.yml. maybe purge attribute can do this. On Monday, February 4, 2013 7:58:37 PM UTC+8, Andriy Yurchuk wrote:> > I''m trying to implement a custom recursive directory synchronization > resource in Puppet. What I need to do is the following. > > I have a YAML file with the list of hostnames and the list of directories > that should exist on each hostname inside, say, `/var/lib/my_app` directory > (`deployment.yml`): > > host_1: > - DIR_1 > - DIR_5 > host_5: > - DIR_7 > host_6: > - DIR_2 > - DIR_3 > - DIR_9 > > On the master I have a directory that contains all of those `DIR_*` > sub-directories. Each subdirectory contains some files. What I''m trying to > achieve is to synchronize all the nodes according to the `deployment.yml`, > so that `/var/lib/my_app` on `host_1` only contains `DIR_1` and `DIR_5`, > but does not contain `DIR_7`, `DIR_2`, `DIR_3`, `DIR_9`, and so on. > > I tried to do this using the ignore variable for file type, but this does > not remove the directories from the node if I remove them from > deployment.yml. I tried to write a custom function to remove them > afterwards, but it does not seem to work inside my manifest. I also wanted > to implement a custom type, but it seems to be too complicated. > > I''d appreciate any help on this. >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Andriy Yurchuk
2013-Feb-04 15:40 UTC
[Puppet Users] Re: Puppet custom recursive directory synchronization
To be able to do this with purge I need to pass the list of subdirectories I want to exist to source attribute, but I''m not sure I can do this On Monday, February 4, 2013 2:57:20 PM UTC+2, 刘长元 wrote:> > "but this does not remove the directories from the node if I remove them > from deployment.yml. maybe purge attribute can do this. > > On Monday, February 4, 2013 7:58:37 PM UTC+8, Andriy Yurchuk wrote: >> >> I''m trying to implement a custom recursive directory synchronization >> resource in Puppet. What I need to do is the following. >> >> I have a YAML file with the list of hostnames and the list of directories >> that should exist on each hostname inside, say, `/var/lib/my_app` directory >> (`deployment.yml`): >> >> host_1: >> - DIR_1 >> - DIR_5 >> host_5: >> - DIR_7 >> host_6: >> - DIR_2 >> - DIR_3 >> - DIR_9 >> >> On the master I have a directory that contains all of those `DIR_*` >> sub-directories. Each subdirectory contains some files. What I''m trying to >> achieve is to synchronize all the nodes according to the `deployment.yml`, >> so that `/var/lib/my_app` on `host_1` only contains `DIR_1` and `DIR_5`, >> but does not contain `DIR_7`, `DIR_2`, `DIR_3`, `DIR_9`, and so on. >> >> I tried to do this using the ignore variable for file type, but this does >> not remove the directories from the node if I remove them from >> deployment.yml. I tried to write a custom function to remove them >> afterwards, but it does not seem to work inside my manifest. I also wanted >> to implement a custom type, but it seems to be too complicated. >> >> I''d appreciate any help on this. >> >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Feb-04 16:32 UTC
[Puppet Users] Re: Puppet custom recursive directory synchronization
On Monday, February 4, 2013 9:40:41 AM UTC-6, Andriy Yurchuk wrote:> > To be able to do this with purge I need to pass the list of subdirectories > I want to exist to source attribute, but I''m not sure I can do this > > On Monday, February 4, 2013 2:57:20 PM UTC+2, 刘长元 wrote: >> >> "but this does not remove the directories from the node if I remove them >> from deployment.yml. maybe purge attribute can do this. >> >> On Monday, February 4, 2013 7:58:37 PM UTC+8, Andriy Yurchuk wrote: >>> >>> I''m trying to implement a custom recursive directory synchronization >>> resource in Puppet. What I need to do is the following. >>> >>> I have a YAML file with the list of hostnames and the list of >>> directories that should exist on each hostname inside, say, >>> `/var/lib/my_app` directory (`deployment.yml`): >>> >>> host_1: >>> - DIR_1 >>> - DIR_5 >>> host_5: >>> - DIR_7 >>> host_6: >>> - DIR_2 >>> - DIR_3 >>> - DIR_9 >>> >>> On the master I have a directory that contains all of those `DIR_*` >>> sub-directories. Each subdirectory contains some files. What I''m trying to >>> achieve is to synchronize all the nodes according to the `deployment.yml`, >>> so that `/var/lib/my_app` on `host_1` only contains `DIR_1` and `DIR_5`, >>> but does not contain `DIR_7`, `DIR_2`, `DIR_3`, `DIR_9`, and so on. >>> >>> I tried to do this using the ignore variable for file type, but this >>> does not remove the directories from the node if I remove them from >>> deployment.yml. I tried to write a custom function to remove them >>> afterwards, but it does not seem to work inside my manifest. I also wanted >>> to implement a custom type, but it seems to be too complicated. >>> >>> I''d appreciate any help on this. >>> >>One reasonably good way to approach this problem is to endow your manifests with the knowledge of the full set of possible DIR_*. You could add that as a separate datum, you could create it by merging all the per-host lists, or you could perhaps create it by listing the server-side directory in which they the master copies live. You can then generate appropriate File resources for every one, specifying whether it should be present or absent. Alternatively, you certainly can do this with an Exec''ed script. You didn''t say much about what you tried in that direction, but something along these lines ought to do the trick: # the join() function comes from the "stdlib" module: $wanted_dirs_pattern = join($wanted_dirs, ''|'') exec { ''clean unwanted myapp/ subdirs'': command => "/bin/bash -c ''for d in /var/lib/my_app/*; do case \$d in $wanted_dirs_pattern) ;; *) /bin/rm -rf \$d;; esac done''" } John -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Andriy Yurchuk
2013-Feb-05 20:05 UTC
[Puppet Users] Re: Puppet custom recursive directory synchronization
I ended up implementing this using Puppet Ruby DSL. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.