Defined Type: wordpress::instance

Defined in:
manifests/instance.pp

Overview

Install a Wordpress instance.

Examples:

Sample installation

include ::wordpress

::wordpress::instance { '/var/www/html':
  owner       => 'apache',
  db_name     => 'wordpress',
  db_user     => 'wordpress',
  db_password => 'secret',
}

Parameters:

  • owner (String)
  • db_name (String)
  • db_user (String)
  • db_password (String)
  • db_host (String) (defaults to: 'localhost')
  • docroot (Stdlib::Absolutepath) (defaults to: $title)
  • auth_key (String) (defaults to: fqdn_rand_string(64, undef, 0))
  • secure_auth_key (String) (defaults to: fqdn_rand_string(64, undef, 1))
  • logged_in_key (String) (defaults to: fqdn_rand_string(64, undef, 2))
  • nonce_key (String) (defaults to: fqdn_rand_string(64, undef, 3))
  • auth_salt (String) (defaults to: fqdn_rand_string(64, undef, 4))
  • secure_auth_salt (String) (defaults to: fqdn_rand_string(64, undef, 5))
  • logged_in_salt (String) (defaults to: fqdn_rand_string(64, undef, 6))
  • nonce_salt (String) (defaults to: fqdn_rand_string(64, undef, 7))
  • group (String) (defaults to: $owner)
  • version (Wordpress::Version) (defaults to: 'latest')

See Also:

Since:

  • 1.0.0



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
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
# File 'manifests/instance.pp', line 33

define wordpress::instance (
  String               $owner,
  String               $db_name,
  String               $db_user,
  String               $db_password,
  String               $db_host          = 'localhost',
  Stdlib::Absolutepath $docroot          = $title,
  String               $auth_key         = fqdn_rand_string(64, undef, 0),
  String               $secure_auth_key  = fqdn_rand_string(64, undef, 1),
  String               $logged_in_key    = fqdn_rand_string(64, undef, 2),
  String               $nonce_key        = fqdn_rand_string(64, undef, 3),
  String               $auth_salt        = fqdn_rand_string(64, undef, 4),
  String               $secure_auth_salt = fqdn_rand_string(64, undef, 5),
  String               $logged_in_salt   = fqdn_rand_string(64, undef, 6),
  String               $nonce_salt       = fqdn_rand_string(64, undef, 7),
  String               $group            = $owner,
  Wordpress::Version   $version          = 'latest',
) {

  if ! defined(Class['::wordpress']) {
    fail('You must include the wordpress base class before using any wordpress defined resources')
  }

  $filename = $version ? {
    'latest' => 'latest.tar.gz',
    default  => "wordpress-${version}.tar.gz",
  }

  if $::selinux {
    # Otherwise Wordpress can't update itself or plugins, etc.
    ::selinux::fcontext { "${docroot}(/.*)?":
      seltype => 'httpd_sys_rw_content_t',
      before  => File[$docroot],
    }

    exec { "restorecon -R ${docroot}":
      path        => $::path,
      refreshonly => true,
      subscribe   => [
        ::Selinux::Fcontext["${docroot}(/.*)?"],
        File[$docroot],
        Archive["/tmp/${filename}"],
        File["${docroot}/wp-config.php"],
      ],
    }
  }

  file { $docroot:
    ensure  => directory,
    owner   => $owner,
    group   => $group,
    mode    => '0644',
    recurse => true,
  }

  archive { "/tmp/${filename}":
    path            => "/tmp/${filename}",
    source          => "https://wordpress.org/${filename}",
    checksum_type   => 'sha1',
    checksum_url    => "https://wordpress.org/${filename}.sha1",
    user            => $owner,
    group           => $group,
    extract         => true,
    extract_command => 'tar xfz %s --strip-components=1',
    extract_path    => $docroot,
    creates         => "${docroot}/index.php",
    require         => File[$docroot],
  }

  file { "${docroot}/wp-config.php":
    ensure  => file,
    owner   => $owner,
    group   => $group,
    mode    => '0644',
    content => template("${module_name}/wp-config.php.erb"),
    require => Archive["/tmp/${filename}"],
  }

  ::mysql::db { $db_name:
    user     => $db_user,
    password => $db_password,
    host     => $db_host,
    grant    => ['ALL'],
  }
}