Ask Your Question
0

exec runs before other commands

asked 2015-09-02 01:37:13 -0500

AG gravatar image

I am creating a group named jboss in puppet and then using exec to run a sed command to make some changes in /etc/group file afterwards.
The problem is that the exec command is running before the group command.

My Yaml file

    group { 'jboss':
        ensure => 'present',
        gid    => "501",
    }
    exec { "modify etc_group":
        command => "/bin/sed -i -e '<regex>' /etc/group",
        path    => "/bin:/usr/bin",
        unless  => "<condition>",
    }

Puppet run output

notice: /Stage[main]/App::Misc/Exec[modify etc_group]/returns: current_value notrun, should be 0 (noop)
notice: /Stage[main]/App::Misc/Group[jboss]/ensure: current_value absent, should be present (noop)

How to make sure that the exec runs after the group command?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2015-09-02 07:42:33 -0500

johnnyb04 gravatar image

updated 2015-09-02 07:43:29 -0500

I recommend reading over Relationships and Ordering. But essentially you could try the "->" chaining arrow. Your code would look something like this.

#Run Group 
group { 'jboss':
        ensure => 'present',
        gid    => "501",
    } -> # and then 
    exec { "modify etc_group":
        command => "/bin/sed -i -e '<regex>' /etc/group",
        path    => "/bin:/usr/bin",
        unless  => "<condition>",
    }
edit flag offensive delete link more
2

answered 2015-09-03 02:44:40 -0500

SimonH gravatar image

updated 2015-09-03 02:48:04 -0500

Another option would be to use the requires clause - this has the advantage that the two components don't need to be adjacent in your code and also that you can have several pre-requisites. Something like:

     group { 'jboss':
        ensure => 'present',
        gid    => "501", }

    exec { "modify etc_group":
        command => "/bin/sed -i -e '<regex>' /etc/group",
        path    => "/bin:/usr/bin",
        unless  => "<condition>",
        require => Group [ 'jboss' ],
    }

There is an associated clause of before which you could add to the group definition:

 group { 'jboss':
    ensure => 'present',
    gid    => "501",
    before => Exec [ 'modify_etc_group' ]
}

exec { "modify etc_group":
    command => "/bin/sed -i -e '<regex>' /etc/group",
    path    => "/bin:/usr/bin",
    unless  => "<condition>",

}

edit flag offensive delete link more

Comments

Hi, above two answers are what you need, however I would recommend avoiding the use of exec if at all possible? Can you say what you're trying to do with the exec - I'm wondering if theres a better way to go about this, best wishes Stuart

sahumphries gravatar imagesahumphries ( 2015-09-03 03:28:49 -0500 )edit
0

answered 2015-09-03 08:15:02 -0500

slk gravatar image

You can also use file_line function from stdlib module.

https://forge.puppetlabs.com/puppetla...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-09-02 01:37:13 -0500

Seen: 607 times

Last updated: Sep 03 '15