kadamwhite / chassis-wxr

Import WordPress WXR files on provision
2 stars 0 forks source link

Validate that control flow is properly implemented #1

Open kadamwhite opened 5 years ago

kadamwhite commented 5 years ago

Tagging @rmccue because after yesterday, I think I don't get along well at all with Puppet (and especially the Puppet docs). An outside opinion would be helpful.

We can't run an import unless the Importer plugin is installed and active. puppet-wp doesn't seem to let me use unless or onlyif on any of its exposed tasks, so chaining appears to be the only way I can ensure that this occurs. Right now we're doing this (simplified for brevity):

  $wxr_path = "${ $config[mapped_paths][content] }/${ $config[wxr][path] }"

  if $config[wxr][clean] == true {
    wp::command { 'wp site empty':
      # These tasks will not run unless WP is installed.
      require  => Chassis::Wp[ $config['hosts'][0] ],
    }

    -> wp::command { 'wp plugin install wordpress-importer'
    -> wp::command { 'wp plugin activate wordpress-importer'

    -> wp::command { "wp import ${ $wxr_path }"
  }
  else {
    wp::command { 'wp plugin install wordpress-importer'
    -> wp::command { 'wp plugin activate wordpress-importer'

    -> wp::command { "wp import ${ $wxr_path }"
  }

Is this the best way to achieve this? What I want to be able to do is to say,

I feel this should be achievable but nothing I can determine about this $@%$%! piece of trash configuration management tool explains in human-readable terms how to make it happen.

(Ansible, if you're out there watching, :two_hearts:. I miss you. Come home.)

rmccue commented 5 years ago

We discussed this a bit in Slack, but to go into a bit further detail here:

Puppet is entirely declarative, so there's no concept of if x, do y (apart from compile-time things), generally speaking. Instead, you say how you want the universe to look, and Puppet works out the internals.

For something like this, what you'd want to generally do is have a resource like:

define wxr::content(
    $path = $title,
) {
    # ...
}

Internally, this would then work out how to make the universe match the declared state. You can break out into Ruby if you want to.

Without doing that, you'd want something like this:

wp::plugin { 'wordpress-importer':
    ensure => enabled,
    require => Chassis::Wp[ $config['hosts'][0] ],
}
if $config[wxr][clean] == true {
    wp::command { 'site empty':
        before => Wp::Command["import $wxr_path"],
        require => Wp::Plugin['wordpress-importer'],
    }
}
wp::command { "import $wxr_path":
    require => Wp::Plugin['wordpress-importer'],
}

(wp::command will only run if it's already installed)