Query with use of recurse

26 views
Skip to first unread message

Balasubramaniam Natarajan

unread,
Sep 2, 2014, 8:43:16 AM9/2/14
to puppet...@googlegroups.com, Balasubramaniam Natarajan
Hi

I have a query regarding how recurse behaves when we call it with "ensure => file"[1] compared with "ensure => directory"[2] ?

Would it make any sense to call recurse with "ensure => file" ?

[1]
  file {'/home/bala':
    ensure=> file,
    source => "puppet:///files/home/bala/",
    sourceselect => "all",
    recurse => true,
  }

[2]
  file {'/home/bala':
    ensure=> directory,
    source => "puppet:///files/home/bala/",
    sourceselect => "all",
    recurse => true,
  }



--
Regards,
Balasubramaniam Natarajan
http://blog.etutorshop.com

Wil Cooley

unread,
Sep 2, 2014, 12:38:58 PM9/2/14
to puppet-users group, Balasubramaniam Natarajan


On Sep 2, 2014 5:43 AM, "Balasubramaniam Natarajan" <bala1...@gmail.com> wrote:
>
> Hi
>
> I have a query regarding how recurse behaves when we call it with "ensure => file"[1] compared with "ensure => directory"[2] ?
>
> Would it make any sense to call recurse with "ensure => file" ?

No, recurse is only useful for copying directory to directory.

What are you going to accomplish? Copying a source directory of symlinks as their targets? If so, there's a separate parameter for that.

Wil

> [1]
>   file {'/home/bala':
>     ensure=> file,
>     source => "puppet:///files/home/bala/",
>     sourceselect => "all",
>     recurse => true,
>   }
>
> [2]
>   file {'/home/bala':
>     ensure=> directory,
>     source => "puppet:///files/home/bala/",
>     sourceselect => "all",
>     recurse => true,
>   }
>
>
>
> --
> Regards,
> Balasubramaniam Natarajan
> http://blog.etutorshop.com
>

> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAFHFDA%3D%3DHjSUdCttzWBizMnaJrNgyR_wM4Ga8NEUZoVgTPE5DA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Balasubramaniam Natarajan

unread,
Sep 3, 2014, 4:49:22 PM9/3/14
to Wil Cooley, puppet-users group


On Tue, Sep 2, 2014 at 10:08 PM, Wil Cooley <wco...@nakedape.cc> wrote:


No, recurse is only useful for copying directory to directory.

What are you going to accomplish? Copying a source directory of symlinks as their targets? If so, there's a separate parameter for that.

Wil


I have a separate UMASK defined.

If I follow [2] puppet changes all the directory permission under /home/bala/ even if they are not included under puppet:///files/home/bala/ to be synced (i.e /home/bala/Documents /home/bala/Downloads /home/bala/Desktop) gets their permission changed. 

If I go with [1] it affects the permission only to the directory which are getting synced off puppet:///files/home/bala/ (i.e /home/bala /home/bala/cow /home/bala/cat /home/bala/tiger).

My ideal goal is to have something like [3] where the permission get enforced only on the directory and subdirectories over-riding the UMASK which I have set previously.  The enforced permission should not get applied on the files which are getting synced (i.e /home/bala/temp.txt).  Currently when I follow [3] it changed the permission of /home/bala/temp.txt to 755 as well.

$ ls files/home/bala/
cow/  cat/  tiger/ temp.txt

[1]
  file {'/home/bala':
    ensure=> file,
    source => "puppet:///files/home/bala/",
    sourceselect => "all",
    recurse => true,
  }

[2]
  file {'/home/bala':
    ensure=> directory,
    source => "puppet:///files/home/bala/",
    sourceselect => "all",
    recurse => true,
  }


[3]

  file {'/home/bala':
    ensure=> directory,
    source => "puppet:///files/home/bala/",
    sourceselect => "all",
    recurse => true,
    mode => "755",

jcbollinger

unread,
Sep 4, 2014, 10:53:29 AM9/4/14
to puppet...@googlegroups.com


On Wednesday, September 3, 2014 3:49:22 PM UTC-5, Balasubramaniam Natarajan wrote:



On Tue, Sep 2, 2014 at 10:08 PM, Wil Cooley <wco...@nakedape.cc> wrote:


No, recurse is only useful for copying directory to directory.

What are you going to accomplish? Copying a source directory of symlinks as their targets? If so, there's a separate parameter for that.

Wil


I have a separate UMASK defined.

If I follow [2] puppet changes all the directory permission under /home/bala/ even if they are not included under puppet:///files/home/bala/ to be synced (i.e /home/bala/Documents /home/bala/Downloads /home/bala/Desktop) gets their permission changed. 



It sounds like you may want recurse => 'remote' instead of recurse => true; see https://docs.puppetlabs.com/references/latest/type.html#file-attribute-recurse.


 
If I go with [1] it affects the permission only to the directory which are getting synced off puppet:///files/home/bala/ (i.e /home/bala /home/bala/cow /home/bala/cat /home/bala/tiger).


As written, [1] is just wrong.  It would convert the named directory to a plain (empty) file (ensure => 'file') if you also specified force => true.  Inasmuch as you did not use 'force', the resource should just fail.  Any behavior associated with the 'sourceselect' and 'recurse' parameters under these circumstances is undocumented and therefore subject to change without notice.

 

My ideal goal is to have something like [3] where the permission get enforced only on the directory and subdirectories over-riding the UMASK which I have set previously.  The enforced permission should not get applied on the files which are getting synced (i.e /home/bala/temp.txt).  Currently when I follow [3] it changed the permission of /home/bala/temp.txt to 755 as well.



If you have explicit File resources for some of the files under your recursively-managed directory, then those should take precedence over any recursively-derived ones.  So, I think this should work for you:

file { '/home/bala':
  ensure  => 'directory',
  source  => 'puppet:///files/home/bala',
  # sourceselect doesn't matter because there's only one source
  recurse => 'remote',
  mode    => '0755'
}

file { '/home/bala/temp.txt':
  ensure => 'file',
  source => 'puppet:///files/home/bala/temp.txt',
  mode   => '0640'
}


John

Reply all
Reply to author
Forward
0 new messages