Ask Your Question
0

Exec and system-wide environment variables (CentOS)

asked 2015-10-24 06:24:27 -0500

naviter gravatar image

Hi, I am setting up a system-wide environment variable so multiple users can use the setting. The issue is that the command executes properly, but I can't get it to run only once - every time I run the puppet agent on the node the exec executes. How can I get the exec to set the DATADIR and only fire if the DATADIR changes for some reason?

#Create the system-wide environment variable file mix.sh and populate it with content

  file { '/etc/profile.d/mix.sh':
    ensure  =>  present,
    content => 'export DATA_DIR=/opt/data/Buildings',
  }

Then the exec: I invoke /etc/profile to run in order to pick up /etc/profile.d/mix.sh and the newly created DATA_DIR environment variable within it. That works fine, but the exec fires every time I run the puppet agent as opposed to only running if there is a change to mix.sh I though that adding the subscribe attribute would control how often the exec ran, but that didn't control it's behavior:

exec { 'add-DATA_DIR ':
  provider => shell, 
  command  => '. /etc/profile',  #use dot command to run the /etc/profile file
  subscribe  => File['/etc/profile.d/mix.sh'], 
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-10-26 03:56:23 -0500

Cristian Falcas gravatar image

The exec resource has a refreshonly parameter:

https://docs.puppetlabs.com/reference...

exec { 'add-DATA_DIR ':
  provider    => shell, 
  command     => '. /etc/profile',  #use dot command to run the /etc/profile file
  subscribe   => File['/etc/profile.d/mix.sh'], 
  refreshonly => true,
}
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

1 follower

Stats

Asked: 2015-10-24 06:16:36 -0500

Seen: 255 times

Last updated: Oct 26 '15