Defined Type: cassandra::schema::user

Defined in:
manifests/schema/user.pp

Overview

Create or drop users. To use this class, a suitable authenticator (e.g. PasswordAuthenticator) must be set in the Cassandra class.

Examples:

cassandra::schema::user { 'akers':
  password  => 'Niner2',
  superuser => true,
}

cassandra::schema::user { 'lucan':
  ensure => absent,
}

Parameters:

  • ensure (present | absent) (defaults to: present)

    Valid values can be present to ensure a user is created, or absent to remove the user if it exists.

  • password (string) (defaults to: undef)

    A password for the user.

  • superuser (boolean) (defaults to: false)

    If the user is to be a super-user on the system.

  • user_name (string) (defaults to: $title)

    The name of the user.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'manifests/schema/user.pp', line 18

define cassandra::schema::user (
  $ensure    = present,
  $password  = undef,
  $superuser = false,
  $user_name = $title,
  ){
  include 'cassandra::schema'
  $read_script = 'LIST USERS'
  $read_command = "${::cassandra::schema::cqlsh_opts} -e \"${read_script}\" ${::cassandra::schema::cqlsh_conn} | grep '\s*${user_name} |'"

  if $ensure == present {
    $create_script1 = "CREATE USER IF NOT EXISTS ${user_name}"

    if $password != undef {
      $create_script2 = "${create_script1} WITH PASSWORD '${password}'"
    } else {
      $create_script2 = $create_script1
    }

    if $superuser {
      $create_script = "${create_script2} SUPERUSER"
    } else {
      $create_script = "${create_script2} NOSUPERUSER"
    }

    $create_command = "${::cassandra::schema::cqlsh_opts} -e \"${create_script}\" ${::cassandra::schema::cqlsh_conn}"

    exec { "Create user (${user_name})":
      command => $create_command,
      unless  => $read_command,
      require => Exec['::cassandra::schema connection test'],
    }
  } elsif $ensure == absent {
    $delete_script = "DROP USER ${user_name}"
    $delete_command = "${::cassandra::schema::cqlsh_opts} -e \"${delete_script}\" ${::cassandra::schema::cqlsh_conn}"

    exec { "Delete user (${user_name})":
      command => $delete_command,
      onlyif  => $read_command,
      require => Exec['::cassandra::schema connection test'],
    }
  } else {
    fail("Unknown action (${ensure}) for ensure attribute.")
  }
}