There are some parameters to the exec type that you could use, such as 
creates, onlyif and unless. However, the pseudocode you have above has the 
execs in your initial if block being run every time puppet runs, it seems. 
Is that really what you want?

On Monday, August 18, 2014 2:45:23 PM UTC-7, Eugene Sapozhnikov wrote:
>
>
>
> I am trying to figure out a way to use a if statement to run multiple sets 
> of commands depending if one file exists, but I am unable to find any good 
> documented ways of doing this.
>
> Basic rough layout of what i would like to achieve is this:
>
> Any help on getting the correct syntax for the if statement would be 
> appreciated 
>
>
>
> if file /volumes/vol1 exists { *exec { generate_loopback_tor: command => 
> "/sbin/losetup /dev/loop6 /volumes/tor", unless => "/sbin/losetup -a| 
> /bin/grep \"/volumes/tor\"", } *
>
> *exec { generate_encrypt_tor:    command => " /sbin/cryptsetup create tor 
> ",    unless => "/usr/bin/test -e /dev/mapper/tor", }exec { 
> generate_mount_tor: command => "/bin/mount /dev/mapper/tor /usr/local/tor", 
> unless => "/bin/mount | /bin/grep \"/usr/local/tor\"", } }* else { exec { 
> generate_empty_file_tor: command => "/bin/dd of=/volumes/tor bs=256M 
> count=0 seek=1", unless => "/usr/bin/test -e /volumes/tor", } exec { 
> generate_loopback_tor: command => "/sbin/losetup /dev/loop6 /volumes/tor", 
> unless => "/sbin/losetup -a| /bin/grep \"/volumes/tor\"", } exec { 
> generate_encrypt_tor: command => "/bin/echo \XXXXXXXXXX\" | 
> /sbin/cryptsetup create tor /dev/loop6 -", unless => "/usr/bin/test -e 
> /dev/mapper/tor", } exec { generate_zero_tor: command => "/bin/dd 
> if=/dev/zero of=/dev/mapper/tor count=512 bs=1024", unless => "/sbin/fdisk 
> -lu | /bin/grep \"/dev/mapper/tor\"", } exec { generate_mkfs_tor: command 
> => "/sbin/mke2fs -j -O dir_index /dev/mapper/tor ", onlyif => "/sbin/parted 
> -l | /bin/grep \"Error: /dev/mapper/tor: unrecognised disk label\"", } exec 
> { generate_mount_tor: command => "/bin/mount /dev/mapper/tor 
> /usr/local/tor", unless => "/bin/mount | /bin/grep \"/usr/local/tor\"", }
>  
>
> }
>
>

-- 
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/9f468d9c-cf7d-4ea6-96bc-1e4c1b6ee155%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to