Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that control flow is properly implemented #1

Open
kadamwhite opened this issue Dec 19, 2018 · 1 comment
Open

Validate that control flow is properly implemented #1

kadamwhite opened this issue Dec 19, 2018 · 1 comment

Comments

@kadamwhite
Copy link
Owner

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,

  • Guarantee me that the importer plugin is installed and active
  • THEN, if clean is set, wipe the content
  • THEN, import the content

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, 💕. I miss you. Come home.)

@rmccue
Copy link

rmccue commented Dec 19, 2018

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants