Puppet Class: rundeck::cli

Defined in:
manifests/cli.pp

Summary

Class to manage installation and configuration of Rundeck CLI.

Overview

Examples:

Use cli with token and project config.

class { 'rundeck::cli':
  manage_repo => false,
  url         => 'https://rundeck01.example.com',
  bypass_url  => 'https://rundeck.example.com',
  token       => 'very_secure',
  projects    => {
    'MyProject'   => {
      'update_method' => 'set',
      'config'        => {
        'project.description'        => 'This is My rundeck project',
        'project.disable.executions' => 'false',
      },
    },
    'TestProject' => {
      'config' => {
        'project.description'      => 'This is a rundeck test project',
        'project.disable.schedule' => 'false',
      },
    },
  },
}

Parameters:

  • repo_config (Hash)

    A hash of repository attributes for configuring the rundeck cli package repositories. Examples/defaults for yumrepo can be found at RedHat.yaml, and for apt at Debian.yaml

  • manage_repo (Boolean) (defaults to: true)

    Whether to manage the cli package repository.

  • notify_conn_check (Boolean) (defaults to: false)

    Wheter to notify the cli connection check if rundeck service changes.

  • version (String[1]) (defaults to: 'installed')

    Ensure the state of the rundeck cli package, either present, absent or a specific version.

  • url (Stdlib::HTTPUrl) (defaults to: 'http://localhost:4440')

    Rundeck instance/api url.

  • bypass_url (Stdlib::HTTPUrl) (defaults to: 'http://localhost:4440')

    Rundeck external url to bypass. This will rewrite any redirect to $bypass_url as $url

  • user (String[1]) (defaults to: 'admin')

    Cli user to authenticate.

  • password (String[1]) (defaults to: 'admin')

    Cli password to authenticate.

  • token (Optional[String[8]]) (defaults to: undef)

    Cli token to authenticate.

  • projects (Hash[String, Rundeck::Project]) (defaults to: {})

    Cli projects config. See example for structure and rundeck::config::project for available params.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'manifests/cli.pp', line 48

class rundeck::cli (
  Hash $repo_config,
  Boolean $manage_repo = true,
  Boolean $notify_conn_check = false,
  String[1] $version = 'installed',
  Stdlib::HTTPUrl $url = 'http://localhost:4440',
  Stdlib::HTTPUrl $bypass_url = 'http://localhost:4440',
  String[1] $user = 'admin',
  String[1] $password = 'admin',
  Optional[String[8]] $token = undef,
  Hash[String, Rundeck::Project] $projects = {},
) {
  ensure_resource('package', 'jq', { 'ensure' => 'present' })

  if $notify_conn_check {
    Class['rundeck::service'] ~> Exec['Check rundeck cli connection']
  }

  case $facts['os']['family'] {
    'RedHat': {
      if $manage_repo {
        $repo_config.each | String $_repo_name, Hash $_attributes| {
          yumrepo { $_repo_name:
            *      => $_attributes,
            before => Package['rundeck-cli'],
          }
        }
      }
    }
    'Debian': {
      if $manage_repo {
        $repo_config.each | String $_repo_name, Hash $_attributes| {
          apt::source { $_repo_name:
            *      => $_attributes,
            before => Package['rundeck-cli'],
          }
        }
      }

      Class['Apt::Update'] -> Package['rundeck-cli']
    }
    default: {
      err("The osfamily: ${facts['os']['family']} is not supported")
    }
  }

  package { 'rundeck-cli':
    ensure => $version,
  }

  file {
    default:
      ensure => file,
      mode   => '0755',
      ;
    '/usr/local/bin/rd_project_diff.sh':
      content => file('rundeck/rd_project_diff.sh'),
      ;
    '/usr/local/bin/rd_job_diff.sh':
      content => file('rundeck/rd_job_diff.sh'),
      ;
  }

  $_default_env_vars = [
    'RD_FORMAT=json',
    "RD_URL=${url}",
    "RD_BYPASS_URL=${bypass_url}",
  ]

  if $token {
    $environment = $_default_env_vars + ["RD_TOKEN=${token}"]
  } else {
    $environment = $_default_env_vars + ["RD_USER=${user}", "RD_PASSWORD=${password}"]
  }

  exec { 'Check rundeck cli connection':
    command     => 'rd system info',
    path        => ['/bin', '/usr/bin', '/usr/local/bin'],
    environment => $environment,
    tries       => 60,
    try_sleep   => 5,
    unless      => 'rd system info &> /dev/null',
    require     => Package['rundeck-cli'],
  }

  $projects.each |$_name, $_attr| {
    rundeck::config::project { $_name:
      *       => $_attr,
      require => Exec['Check rundeck cli connection'],
    }
  }
}