class apache { user { 'webUser' : ensure => present } ... } node default { include apache }
class apache { user { 'webUser' : ensure => present } } class nginx { user { 'webUser' : ensure => present } } node default { include apache include nginx }
root@puppet:/vagrant# puppet apply ./site.pp --noop Error: Duplicate declaration: User[webUser] is already declared in file /vagrant/site.pp:17; cannot redeclare at /vagrant/site.pp:11 on node puppet.example.com Error: Duplicate declaration: User[webUser] is already declared in file /vagrant/site.pp:17; cannot redeclare at /vagrant/site.pp:11 on node puppet.example.com
class users { user { 'webUser' : ensure => present } } class nginx { include users } class apache { include users } node default { include apache include nginx }
root@puppet:/vagrant# puppet apply ./site.pp --noop Notice: Compiled catalog for puppet.example.com in environment production in 0.07 seconds Notice: /Stage[main]/users/User[webUser]/ensure: current_value absent, should be present (noop) Notice: Class[users]: Would have triggered 'refresh' from 1 events Notice: Stage[main]: Would have triggered 'refresh' from 1 events Notice: Finished catalog run in 0.02 seconds
class users { user { 'webUser': ensure => present } user { 'cacheUser': ensure => present } }
@user { 'webUser': ensure => present }
The virtual resource declaration
class users { @user { 'webUser': ensure => present } @user { 'cacheUser': ensure => present } } class nginx { include users } class apache { include users } node default { include apache include nginx }
root@puppet:/vagrant# puppet apply ./site.pp Notice: Compiled catalog for puppet.example.com in environment production in 0.07 seconds Notice: Finished catalog run in 0.02 seconds
class apache { @user { 'webUser' : ensure => present } } class nginx { @user { 'webUser' : ensure => present } } node default { include apache include nginx }
class users { @user { 'webUser': ensure => present } @user { 'cacheUser': ensure => present } } class nginx { include users realize User['webUser'], User['cacheUser'] } class apache { include users User <| title == 'webUser' or title == 'cacheUser' |> } node default { include apache include nginx }
Error: Failed to realize virtual resources User[nonExistingUser] on node puppet.example.com
class configurations { file { '/etc/nginx.conf' : ensure => present } file { '/etc/apache2.conf' : ensure => present } } node s1.example.com { include configurations } node s2.example.com { include configurations File <| title == '/etc/apache2.conf' |> { ensure => absent } }
Yumrepo <| |> -> Package <| |>
class ssh { # Declare: @@sshkey { $hostname: type => dsa, key => $sshdsakey, } # Collect: Sshkey <<| |>> }
# "server IP:PORT;" upstream nginx class nginx::backend($ip = $::ipaddress, $port = 8080) { @@concat::fragment { "$::fqdn" : content => "server $ip:$port;", tag => 'nginx-backend', target => '/etc/nginx/conf.d/backend.conf' } } # , concat, nginx::backend class nginx::frontend { concat { '/etc/nginx/backend.conf' : ensure => present, force => true, ensure_newline => true } ~> Class['::nginx::service'] concat::fragment { 'upstream_header': content => 'upstream backend { ', order => '01', target => '/etc/nginx/backend.conf', } concat::fragment { 'upstream_footer' : content => '}', order => '03', target => '/etc/nginx/backend.conf' } # Concat::Fragment <<| tag == 'nginx-backend' |>> { target => '/etc/nginx/backend.conf', order => '02' } } class nginx::install { package { 'nginx' : ensure => present } } class nginx::service { service { 'nginx' : ensure => running, require => Class['nginx::install'] } } class nginx { class { 'nginx::install' : } -> class { 'nginx::service': } } node 'back1.example.com' { class { 'nginx' : } class { 'nginx::backend' : port => 8083 } } node 'back2.example.com' { class { 'nginx' : } class { 'nginx::backend' : port => 8084 } } node 'front1.example.com' { class { 'nginx' : } class { 'nginx:::frontend' : } }
Source: https://habr.com/ru/post/242123/
All Articles