Skip to content

Commit

Permalink
(CONT-359) Syntax update
Browse files Browse the repository at this point in the history
Code now compliant with rules regarding:

legacy facts
  • Loading branch information
LukasAud committed Feb 1, 2023
1 parent 8c5ba7b commit 08a16b2
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 55 deletions.
1 change: 0 additions & 1 deletion .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
--relative
--no-parameter_types-check
--no-parameter_documentation-check
--no-legacy_facts-check
--no-top_scope_facts-check
--no-anchor_resource-check
--no-relative_classname_reference-check
Expand Down
1 change: 0 additions & 1 deletion .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Rakefile:
extra_disabled_lint_checks:
- parameter_types
- parameter_documentation
- legacy_facts
- top_scope_facts
- anchor_resource
- relative_classname_reference
Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ end
PuppetLint.configuration.send('disable_relative')
PuppetLint.configuration.send('disable_parameter_types')
PuppetLint.configuration.send('disable_parameter_documentation')
PuppetLint.configuration.send('disable_legacy_facts')
PuppetLint.configuration.send('disable_top_scope_facts')
PuppetLint.configuration.send('disable_anchor_resource')
PuppetLint.configuration.send('disable_relative_classname_reference')
Expand Down
4 changes: 2 additions & 2 deletions examples/mysql_db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
host => 'localhost',
grant => ['SELECT', 'UPDATE'],
}
mysql::db { "mydb_${fqdn}":
mysql::db { "mydb_${facts['networking']['fqdn']}":
user => 'myuser',
password => 'mypass',
dbname => 'mydb',
host => $::fqdn,
host => $facts['networking']['fqdn'],
grant => ['SELECT', 'UPDATE'],
tag => $domain,
}
2 changes: 1 addition & 1 deletion examples/mysql_login_path.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
include apt
apt::source { 'repo.mysql.com':
location => 'http://repo.mysql.com/apt/debian',
release => $::lsbdistcodename,
release => $facts['os']['distro']['codename'],
repos => 'mysql-8.0',
key => {
id => 'A4A9406876FCBD3C456770C88C718D3B5072E1F5',
Expand Down
4 changes: 2 additions & 2 deletions examples/mysql_plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
root_password => 'password',
}

$validate_password_soname = $::osfamily ? {
$validate_password_soname = $facts['os']['family'] ? {
'windows' => 'validate_password.dll',
default => 'validate_password.so'
}
Expand All @@ -12,7 +12,7 @@
soname => $validate_password_soname,
}

$auth_socket_soname = $::osfamily ? {
$auth_socket_soname = $facts['os']['family'] ? {
'windows' => 'auth_socket.dll',
default => 'auth_socket.so'
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/backup/mysqlbackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
}

if $install_cron {
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
ensure_packages('cronie')
} elsif $::osfamily != 'FreeBSD' {
} elsif $facts['os']['family'] != 'FreeBSD' {
ensure_packages('cron')
}
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$backuppassword
}

unless $::osfamily == 'FreeBSD' {
unless $facts['os']['family'] == 'FreeBSD' {
if $backupcompress and $compression_command == 'bzcat -zc' {
ensure_packages(['bzip2'])
Package['bzip2'] -> File['mysqlbackup.sh']
Expand Down Expand Up @@ -69,9 +69,9 @@
}

if $install_cron {
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
ensure_packages('cronie')
} elsif $::osfamily != 'FreeBSD' {
} elsif $facts['os']['family'] != 'FreeBSD' {
ensure_packages('cron')
}
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/backup/xtrabackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
}

if $install_cron {
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
ensure_packages('cronie')
} elsif $::osfamily != 'FreeBSD' {
} elsif $facts['os']['family'] != 'FreeBSD' {
ensure_packages('cron')
}
}
Expand All @@ -138,7 +138,7 @@
}

# Wether to use GNU or BSD date format.
case $::osfamily {
case $facts['os']['family'] {
'FreeBSD','OpenBSD': {
$dateformat = '$(date -v-sun +\\%F)_full'
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/bindings.pp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
$daemon_dev_package_name = $mysql::params::daemon_dev_package_name,
$daemon_dev_package_provider = $mysql::params::daemon_dev_package_provider
) inherits mysql::params {
case $::osfamily {
case $facts['os']['family'] {
'Archlinux': {
if $java_enable { fail("::mysql::bindings::java cannot be managed by puppet on ${::facts['os']['family']} as it is not in official repositories. Please disable java mysql binding.") }
if $perl_enable { include 'mysql::bindings::perl' }
Expand Down
46 changes: 23 additions & 23 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,35 @@
$daemon_dev_package_ensure = 'present'
$daemon_dev_package_provider = undef

case $::osfamily {
case $facts['os']['family'] {
'RedHat': {
case $::operatingsystem {
case $facts['os']['name'] {
'Fedora': {
if versioncmp($::operatingsystemrelease, '19') >= 0 or $::operatingsystemrelease == 'Rawhide' {
if versioncmp($facts['os']['release']['full'], '19') >= 0 or $facts['os']['release']['full'] == 'Rawhide' {
$provider = 'mariadb'
} else {
$provider = 'mysql'
}
$python_package_name = 'MySQL-python'
}
'Amazon': {
if versioncmp($::operatingsystemrelease, '2') >= 0 {
if versioncmp($facts['os']['release']['full'], '2') >= 0 {
$provider = 'mariadb'
} else {
$provider = 'mysql'
}
}
/^(RedHat|Rocky|CentOS|Scientific|OracleLinux|AlmaLinux)$/: {
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
if versioncmp($facts['os']['release']['major'], '7') >= 0 {
$provider = 'mariadb'
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
if versioncmp($facts['os']['release']['major'], '8') >= 0 {
$xtrabackup_package_name = 'percona-xtrabackup-24'
}
} else {
$provider = 'mysql'
$xtrabackup_package_name = 'percona-xtrabackup-20'
}
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
if versioncmp($facts['os']['release']['major'], '8') >= 0 {
$java_package_name = 'mariadb-java-client'
$python_package_name = 'python3-PyMySQL'
} else {
Expand Down Expand Up @@ -119,7 +119,7 @@
}

'Suse': {
case $::operatingsystem {
case $facts['os']['name'] {
'OpenSuSE': {
$socket = '/var/run/mysql/mysql.sock'
$log_error = '/var/log/mysql/mysqld.log'
Expand All @@ -141,7 +141,7 @@
$basedir = undef
}
default: {
fail("Unsupported platform: puppetlabs-${module_name} currently doesn\'t support ${::operatingsystem}.")
fail("Unsupported platform: puppetlabs-${module_name} currently doesn\'t support ${facts['os']['name']}.")
}
}
$config_file = '/etc/my.cnf'
Expand Down Expand Up @@ -207,26 +207,26 @@
$managed_dirs = ['tmpdir','basedir','datadir','innodb_data_home_dir','innodb_log_group_home_dir','innodb_undo_directory','innodb_tmpdir']

# mysql::bindings
if ($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '10') >= 0) or
($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) {
if ($facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['full'], '10') >= 0) or
($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '20.04') >= 0) {
$java_package_name = 'libmariadb-java'
} else {
$java_package_name = 'libmysql-java'
}
$perl_package_name = 'libdbd-mysql-perl'
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '16.04') >= 0) or
($::operatingsystem == 'Debian') {
if ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '16.04') >= 0) or
($facts['os']['name'] == 'Debian') {
$php_package_name = 'php-mysql'
} else {
$php_package_name = 'php5-mysql'
}
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '16.04') < 0) or
($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) or
($::operatingsystem == 'Debian') {
if ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '16.04') < 0) or
($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '20.04') >= 0) or
($facts['os']['name'] == 'Debian') {
$xtrabackup_package_name = 'percona-xtrabackup-24'
}
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) or
($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '11') >= 0) {
if ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '20.04') >= 0) or
($facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['full'], '11') >= 0) {
$python_package_name = 'python3-mysqldb'
} else {
$python_package_name = 'python-mysqldb'
Expand Down Expand Up @@ -340,7 +340,7 @@
$config_file = '/etc/my.cnf'
$includedir = undef
$datadir = '/var/mysql'
$log_error = "/var/mysql/${::hostname}.err"
$log_error = "/var/mysql/${facts['os']['hostname']}.err"
$pidfile = '/var/mysql/mysql.pid'
$root_group = 'wheel'
$mysql_group = '_mysql'
Expand All @@ -365,7 +365,7 @@
}

default: {
case $::operatingsystem {
case $facts['os']['name'] {
'Alpine': {
$client_package_name = 'mariadb-client'
$server_package_name = 'mariadb'
Expand Down Expand Up @@ -425,13 +425,13 @@
}

default: {
fail("Unsupported platform: puppetlabs-${module_name} currently doesn\'t support ${::osfamily} or ${::operatingsystem}.")
fail("Unsupported platform: puppetlabs-${module_name} currently doesn\'t support ${facts['os']['family']} or ${facts['os']['name']}.")
}
}
}
}

case $::operatingsystem {
case $facts['os']['name'] {
'Ubuntu': {
$server_service_provider = 'systemd'
}
Expand Down Expand Up @@ -516,7 +516,7 @@
}

## Additional graceful failures
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '4' and $::operatingsystem != 'Amazon' {
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '4' and $facts['os']['name'] != 'Amazon' {
fail("Unsupported platform: puppetlabs-${module_name} only supports RedHat 6.0 and beyond.")
}
}
14 changes: 7 additions & 7 deletions manifests/server/account_security.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
if ($::fqdn != 'localhost.localdomain') {
if ($facts['networking']['fqdn'] != 'localhost.localdomain') {
mysql_user {
['[email protected]',
'@localhost.localdomain']:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
}
if ($::fqdn and $::fqdn != 'localhost') {
if ($facts['networking']['fqdn'] and $facts['networking']['fqdn'] != 'localhost') {
mysql_user {
["root@${::fqdn}",
"@${::fqdn}"]:
["root@${facts['networking']['fqdn']}",
"@${facts['networking']['fqdn']}"]:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
}
if ($::fqdn != $::hostname) {
if ($::hostname != 'localhost') {
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
if ($facts['networking']['fqdn'] != $facts['networking']['hostname']) {
if ($facts['networking']['hostname'] != 'localhost') {
mysql_user { ["root@${facts['networking']['hostname']}", "@${facts['networking']['hostname']}"]:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
Expand Down
4 changes: 2 additions & 2 deletions readmes/README_ja_JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ mysql::db { 'mydb':
エクスポートされたリソースを含む別のリソース名を使用するには、次のようにします。

```puppet
@@mysql::db { "mydb_${fqdn}":
@@mysql::db { "mydb_${facts['networking']['fqdn']}":
user => 'myuser',
password => 'mypass',
dbname => 'mydb',
host => ${fqdn},
host => ${facts['networking']['fqdn']},
grant => ['SELECT', 'UPDATE'],
tag => $domain,
}
Expand Down
18 changes: 12 additions & 6 deletions spec/classes/mysql_server_account_security_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
context 'with fqdn==myhost.mydomain' do
let(:facts) do
facts.merge(root_home: '/root',
fqdn: 'myhost.mydomain',
hostname: 'myhost')
networking: {
fqdn: 'myhost.mydomain',
hostname: 'myhost'
})
end

['[email protected]',
Expand Down Expand Up @@ -46,8 +48,10 @@
context 'with fqdn==localhost' do
let(:facts) do
facts.merge(root_home: '/root',
fqdn: 'localhost',
hostname: 'localhost')
networking: {
fqdn: 'localhost',
hostname: 'localhost'
})
end

['[email protected]',
Expand All @@ -65,8 +69,10 @@
context 'with fqdn==localhost.localdomain' do
let(:facts) do
facts.merge(root_home: '/root',
fqdn: 'localhost.localdomain',
hostname: 'localhost')
networking: {
fqdn: 'localhost.localdomain',
hostname: 'localhost'
})
end

['[email protected]',
Expand Down

0 comments on commit 08a16b2

Please sign in to comment.