Exec provider shell with 'for' loop

1,292 views
Skip to first unread message

Antidot SAS

unread,
Feb 29, 2012, 5:04:56 AM2/29/12
to puppet-users
Hi everyone,

I am trying to exec the following command:

    exec { 'Apply all kernel variables' :
        path        => '/bin:/usr/bin:/usr/local/bin',
        user        => 'root',
        logoutput   => true,
        provider    => shell,
        command     => "for file in ${config_file} ${config_dir}/*.conf
                        do
                            [ -r \"\${file}\" ] && (echo Applying \"\${file}\" && /sbin/sysctl -q -p \"\${file}\")
                        done",
        refreshonly => true,
    }
Here is the output:
err: /Stage[main]/Sysctl/Exec[Apply all kernel variables]: Failed to call refresh: for file in /etc/sysctl.conf /etc/sysctl.d/*.conf                                                                                                                              do
                                                        [ -r "${file}" ] && (echo Applying "${file}" && /sbin/sysctl -q -p "${file}")
                                                done returned 1 instead of one of [0] at /etc/puppet/modules/sysctl/manifests/init.pp:93


Is simply doesn't work, I know that there are some special behavior with the exec ressource. Of course the following exec works:
    exec { 'Apply all kernel variables' :
        path        => '/bin:/usr/bin:/usr/local/bin',
        user        => 'root',
        logoutput   => true,
        provider    => shell,
        command     => 'for file in /etc/sysctl.conf /etc/sysctl.d/*.conf
                        do
                            [ -r "\${file}" ] && (echo Applying "\${file}" && /sbin/sysctl -q -p "\${file}")
                        done',
        refreshonly => true,
    }


I have extremely big trouble using " instead of ', any idea?

Regards,
JM

Elias Abacioglu

unread,
Feb 29, 2012, 4:58:17 PM2/29/12
to puppet...@googlegroups.com

Antidot SAS skrev 2012-02-29 11:04:
>
> I have extremely big trouble using " instead of ', any idea?
>

You could try replacing double escaping \\ and see if that works.

Perhaps it's simpler if you have file { /tmp/script.sh : content => "for
...$variable" }
or using a template and create a .erb file that is uploaded.

Antidot SAS

unread,
Feb 29, 2012, 7:12:08 PM2/29/12
to puppet...@googlegroups.com

Thx I'll think about it.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Reply all
Reply to author
Forward
0 new messages