Score:0

Puppet: Create user account and use its UID/GID in dependent resource

in flag

I would like Puppet to do the following on the host:

  • Ensure a user named myuser exists.
    • I don't want to hardcode the UID as there are several users created this way.
  • Use the UID of myuser in a shell script (unfortunately username won't do).

So far I have:

user { 'myuser':
    ensure => present,
    system => true,
}

file { '/opt/myuser-uid':
    ensure   => file,
    contents => User['myuser']['uid'],
}

However, the file contents ends up blank.

How can I write the newly created UID to a file?

cn flag
Is it populated on a second run? Remember Puppet is declarative so if the resource doesn't exist at catalog compile-time then it won't be in the file. But I'd expect it to appear subsequently.
in flag
No, it looks like `User['myuser']` only contains what I put in there, and not the UID.
cn flag
In which case you either need to write a custom fact, or manage the user's ID I think.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.