1
votes

I need to remove a few files when in development environment (for example when using Vagrant) but not in production. I want to disable firewalld when in development, but not in production. I would like to disable selinux whenon development, but not on production.

What is the best practice for doing these? I would like to use my puppet scripts both on development environments (with Vagrant) and on production.

1

1 Answers

4
votes

It is not a good practice to have scripts specific to an environment. Instead you should have scripts which will behave differently based on environment. Let me show you how; there are two steps you will need to do for this to work:

  1. Define environments

You will have to define environments - I would suggest directory based environments (Because config based environment support will be dropped eventually). How to setup environments is an intimate topic and I suggest you check out the documentation

  1. Use environments in your code

Let's say you have defined environments such as dev, qa, uat, prod etc. You can get the name of current environment by using $environment variable. Your manifests should leverage the environment variable to decide weather a firewall should be enabled/disabled etc. For example:

(Modified based on Felix's comment, thanks @Felix)

include profile::webserver
if $environment != 'dev'
    include profile::firewall

In above piece of code if the $environment does not match to "dev" only then the firewall role is applied!