Ask Your Question
1

What does the '?' do in a variable definition ?

asked 2013-09-16 11:30:52 -0500

spuder gravatar image

I'm looking at the source for gitlab puppet and I see the following syntax

$foo = $bar ? { }

What does the question mark do?

  $gitlab_without_gems = $gitlab_dbtype ? {
    mysql => 'postgres',
    pgsql => 'mysql',
  }

  # determine pre-requisite packages
  case $::osfamily {
    'Debian': {
      # database packages
      $db_packages = $gitlab_dbtype ? {
        mysql => ['libmysql++-dev','libmysqlclient-dev'],
        pgsql => ['libpq-dev', 'postgresql-client'],
      }

      # system packages
      $system_packages = ['libicu-dev','python2.7','python-docutils',
                          'libxml2-dev','libxslt1-dev','python-dev']
    }
    'RedHat': {
      # database packages
      $db_packages = $gitlab_dbtype ? {
        mysql => ['mysql-devel'],
        pgsql => ['postgresql-devel'],
      }
      $system_packages = ['perl-Time-HiRes','libicu-devel','libxml2-devel',
                          'libxslt-devel','python-devel','libcurl-devel',
                          'readline-devel','openssl-devel','zlib-devel',
                          'libyaml-devel']
    }
    default: {
      err "${::osfamily} not supported yet"
    }
  }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2013-09-16 11:36:30 -0500

spuder gravatar image

This is one of the formats you can use to select one variable from a list

http://docs.puppetlabs.com/learning/variables.html

See the example given in the documentation

$apache = $operatingsystem ? {
      centos                => 'httpd',
      redhat                => 'httpd',
      /(?i)(ubuntu|debian)/ => 'apache2',
      default               => undef,
    }

You could alternatively use a case statement

case $operatingsystem {
        'CentOs': { 
            $apache     = 'httpd'
        }
        'Debian' : { 
            $apache     = 'httpd2'
        }
        default : { 
            $apache = 'http' 
        }
    }
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: 2013-09-16 11:30:52 -0500

Seen: 513 times

Last updated: Sep 16 '13