Bug #4560

Virtual resources inside definitions not properly realized by tag

Added by Ian Ward Comfort almost 2 years ago. Updated over 1 year ago.

Status:Accepted Start date:08/17/2010
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
Affected Puppet version:0.25.5 Branch:
Keywords:realize virtual resource definition tag
Votes: 0

Description

This problem bit my production environment, running 0.25.5, but I can reproduce the problem with 2.6.1rc2, so I’m filing against that.

Consider this sample manifest:

define mydef { @notify { $name: } }
mydef { 'foo': }
Notify<| tag == 'mydef' |>

Given the metaparameter documentation for ‘tag’, I would expect this manifest to generate a real notify resource and a message at catalog-run time, but it does not.

If the last line is change to Notify<||>, to realize all virtual notify resources, the notification appears properly.

More curiously, if the definition is changed to define mydef { @notify { $name: tag => 'mydef' } }, with an explicit tag of the definition name, the notification also appears properly.

History

Updated by Cody Herriges almost 2 years ago

  • Status changed from Unreviewed to Needs More Information

While I and another have been able to reproduce and verify this against the documentation I am curious what your use case is for this functionality.

Updated by Ian Ward Comfort almost 2 years ago

Sure. I’ll try to be brief but my use-case is a little involved.

I often use custom definitions to encapsulate functionality within modules, but still allow multiple modules to interact with each other. I have a postfix module that manages Postfix on all my hosts — MTAs, final-delivery mailhosts, as well as null clients. I also have a user module which handles all my user accounts.

I want my human & system user accounts to be treated differently by Postfix — for example, on a null client nc.stanford.edu I want to send email as icomfort@stanford.edu, but I want system mail to come from, e.g., root@nc.stanford.edu and apache@nc.stanford.edu. I effect this by leaving $myorigin alone and adding a canonical mapping for icomfort –> icomfort@stanford.edu. On a mail gateway, however, I want a virtual mapping that sends icomfort’s mail to my preferred mailhost; say icomfort@stanford.edu –> icomfort@mh.stanford.edu.

My user module passes information to the postfix module about which users are human using a custom definition, postfix::human. This is pseudo-code but it captures the design well enough.

$mail_domain = 'stanford.edu'
$user_mail_host = 'mh.stanford.edu'

define user::human {
  user { $name: }
  postfix::human { $name: }
}

define postfix::human {
  @postfix::canonical { $name:
    address => "$name@$mail_domain",
  }
  @postfix::virtual { "$name@$mail_domain":
    address => "$name@$user_mail_host",
  }
}

class postfix::nullclient {
  Postfix::Canonical<| tag == 'postfix::human' |>
}

class postfix::gateway {
  Postfix::Virtual<| tag == 'postfix::human' |>
}

user::human { 'icomfort': }

I can’t realize all canonical or (Postfix-)virtual mappings in my postfix subclasses because I use (Puppet-)virtual mapping resources for other functionality, as well.

Updated by Cody Herriges over 1 year ago

  • Status changed from Needs More Information to Investigating

I am going to write an acceptance test or two to document this. In the mean time I would just suggest to make the following change to your initial define example.

define mydef { @notify { $name: tag => mydef } }
    mydef { 'foo': }
    Notify<| tag == 'mydef' |>

Updated by Ian Ward Comfort over 1 year ago

Yep, that’s what I’ve been doing as a workaround.

Updated by Cody Herriges over 1 year ago

  • Status changed from Investigating to Accepted

Tags get implicitly assigned based on the documentation at http://projects.puppetlabs.com/projects/puppet/wiki/Using_Tags for non-virtual resources properly. When the resource is virtual and inside a define the resource isn’t implicitly tagged with the define’s resource title. If you explicitly tag the virtual resource within the define it works at expected, getting tagged properly.

I have written three acceptance tests at my puppet-acceptance branch, http://github.com/ody/puppet-acceptance/tree/ticket/4560. These are:

ticket_4560_virtual_resources_inside_definitions_not_properly_realized_by_tag_explicit.sh ticket_4560_virtual_resources_inside_definitions_not_properly_realized_by_tag_implicit.sh ticket_4560_virtual_resources_inside_definitions_not_properly_realized_by_tag_not_virtual_implicit.sh

The first will return 0 and the second will return 10, or EXIT_OK and EXIT_FAILURE. Sorry but the third doesn’t have a sane return value as my file parsing/yaml foo isn’t currently good enough to validate the catalog after the run of the client. Though you can open the catalog file yourself and verify the proper implicit tagging of a non-virtual resource.

Updated by Jesse Wolfe over 1 year ago

  • Affected Puppet version changed from 2.6.1rc2 to 0.25.5

Moved the affected version back to the oldest known appearance.

Also available in: Atom PDF