I am confused about the puppet class/define execution ordering.
I wrote a module named 'mysql', manifests follow:

*mysql/manifests/init.pp*

> class mysql($base_dir='/usr/local/mysql') {
>     class { 'mysql::install':
>         base_dir      => $base_dir,
>     }
> }
>

*mysql/manifests/install.pp*

> class mysql::install($base_dir) {
>     group { 'mysql':
>         ensure     => present,
>     }
>     user { 'mysql':
>         ensure     => present,
>         gid        => 'mysql',
>         shell      => '/sbin/nologin',
>         managehome => false,
>         require    => Group['mysql'],
>     }
>     exec { 'download_mariadb_binary':
>         path       => '/bin:/usr/bin',
>         cwd        => '/tmp',
>         timeout    => 0,
>         command    => 'curl -OL 
> http://mirror.yongbok.net/mariadb/mariadb-5.2.12/kvm-bintar-hardy-amd64/mariadb-5.2.12-Linux-x86_64.tar.gz',
>         logoutput  => on_failure,
>         creates    => '/tmp/mariadb-5.2.12-Linux-x86_64.tar.gz',
>         require    => User['mysql'],
>     }
>     exec { 'install_mariadb_binary':
>         path       => '/bin:/usr/bin',
>         cwd        => '/tmp',
>         command    => "tar xzfP mariadb-5.2.12-Linux-x86_64.tar.gz && mv 
> mariadb-5.2.12-Linux-x86_64 $base_dir",
>         logoutput  => on_failure,
>         creates    => "${base_dir}/bin/mysql",
>         require    => Exec['download_mariadb_binary']
>     }
>     file { $base_dir:
>         ensure     => directory,
>         require    => Exec['install_mariadb_binary'],
>     }
>     file { "${base_dir}/scripts/start_db.sh":
>         ensure     => present,
>         owner      => 'root',
>         group      => 'root',
>         mode       => '0755',
>         source     => 'puppet:///modules/mysql/start_db.sh',
>         require    => File[$base_dir],
>     }
>     file { "${base_dir}/scripts/setup_mariadb.sh":
>         ensure     => present,
>         owner      => 'root',
>         group      => 'root',
>         mode       => '0755',
>         source     => 'puppet:///modules/mysql/setup_mariadb.sh',
>         require    => File[$base_dir],
>     }
>     file { "/tmp/stub_my.cnf":
>         ensure     => present,
>         mode       => '0755',
>         source     => 'puppet:///modules/mysql/stub_my.cnf',
>     }
> }
>

*mysql/manifests/instance.pp*

> define mysql::instance(
>     $bind_address='127.0.0.1',
>     $port='3306',
>     $extra_port='3991',
>     $base_dir='/usr/local/mysql',
>     $data_dir='/var/lib/mysql',
>     $root_password
>     ) {
>     exec { 'create_mysql_instance':
>         path       => "/bin:/sbin:/usr/bin:/usr/sbin",
>         cwd        => '/tmp',
>         command    => "sh ${base_dir}/scripts/setup_mariadb.sh \
> --name=${title} \
> --stub=/tmp/stub_my.cnf \
> --bind=$bind_address \
> --port=$port \
> --extra-port=$extra_port \
> --basedir=$base_dir \
> --datadir=$data_dir \
> --root-password=$root_password",
>         logoutput  => on_failure,
>         creates    => "/etc/mysql/my_${instance}.cnf",
>     }
> }
>

now I wrote a smoke test like this:
mysql/tests/init.pp

> class { 'mysql':
>     base_dir      => '/usr/local/mysql'
> }
> mysql::instance { 'test':
>     root_password => 'rootpassword'
> }
> Class['mysql'] -> Mysql::Instance['test']
>

When I run this smoke test using `puppet apply --noop 
/etc/puppet/modules/mysql/tests/init.pp`, the output log follows:

> notice: /Stage[main]/Mysql::Install/Exec[download_mariadb_binary]/returns: 
> executed successfully
> notice: /Stage[main]/Mysql::Install/Exec[install_mariadb_binary]/returns: 
> executed successfully
> notice: /File[/usr/local/mysql]/owner: owner changed '1001' to 'root'
> notice: /File[/usr/local/mysql]/group: group changed '1001' to 'root'
> notice: /File[/usr/local/mysql]/seluser: seluser changed 'unconfined_u' to 
> 'system_u'
> notice: /File[/usr/local/mysql]/seltype: seltype changed 'user_tmp_t' to 
> 'usr_t'
> err: 
> /Stage[main]//Node[localhost.localdomain]/Mysql::Instance[test]/Exec[create_mysql_instance]/returns:
>  
> change from notrun to 0 failed: sh: /usr/local/mysql/scrip
> ts/setup_mariadb.sh: No such file or directory
>

Why Mysql::Instance['test'] execute before 
File["${base}/scripts/setup_mariadb.sh"]
As U see, I have wrote *Class['mysql'] -> Mysql::Instance['test']*,
and when I wrote *Class['mysql::install'] -> Class['mysql'] -> 
Mysql::Instance['test']*,
the execution order is right

> notice: /Stage[main]/Mysql::Install/Exec[download_mariadb_binary]/returns: 
> current_value notrun, should be 0 (noop)
> notice: /Stage[main]/Mysql::Install/Exec[install_mariadb_binary]/returns: 
> current_value notrun, should be 0 (noop)
> notice: /File[/usr/local/mysql]/ensure: current_value absent, should be 
> directory (noop)
> notice: /File[/usr/local/mysql/scripts/start_db.sh]/ensure: current_value 
> absent, should be file (noop)
> notice: /Stage[main]/Mysql::Install/File[/tmp/stub_my.cnf]/ensure: 
> current_value absent, should be file (noop)
> notice: /File[/usr/local/mysql/scripts/setup_mariadb.sh]/ensure: 
> current_value absent, should be file (noop)
> notice: Class[Mysql::Install]: Would have triggered 'refresh' from 7 events
> notice: 
> /Stage[main]//Mysql::Instance[test]/Exec[create_mysql_instance]/returns: 
> current_value notrun, should be 0 (noop)
>

Sorry my bad English, who can help me!

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/PEUOeHwysMoJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to