Ask Your Question

usermod not working in exec

asked 2016-04-04 01:01:13 -0500

queszama gravatar image

updated 2016-04-04 02:14:51 -0500

I am trying to add a unix user using user resource as follows

      node '',''{
      user {
        ensure  => 'present',
        managehome => 'true',
        comment => 'PuppetGenerated User',
        home    => '/home/thera',
        shell   => '/bin/bash',
        expiry  => '2016-08-24',
        password_min_age => '26',
        password_max_age => '60',
           exec {
              path => ['/usr/bin/','/usr/sbin'],
              command => "usermod -p '$1$Sdqi/D28$DuBGUVe3h6b7z30csGGWN/' thera;chage -d 0 thera",
              subscribe => User['thera'],
              refreshonly => true,

The exec resource does two tasks 1. Set a default password using usermod and then 2 chage to force the user to change his default password.

The issue for me is that the default password is not set as defined , it is making some /D28/ entry . but chage seems is doing its task perfectly.

          # grep thera /etc/shadow
        [root@node3 ~]# chage -l thera
        Last password change      : password must be changed
        Password expires             : password must be changed
        Password inactive            : password must be changed
        Account expires               : Aug 24, 2016
        Minimum number of days between password change          : 26
        Maximum number of days between password change          : 60
        Number of days of warning before password expires       : 7

If I execute the usermod command manually from command line , it is working as expected

       ` usermod -p '$1$Sdqi/D28$DuBGUVe3h6b7z30csGGWN/' thera`
       `grep thera /etc/shadow `

But If I remove the quotes from the password in usermod command , it creates the same :/D28/: entry

       ` # usermod -p $1$Sdqi/D28$DuBGUVe3h6b7z30csGGWN/ thera
        [root@node3 ~]# grep thera /etc/shadow

So looks like somehow it is not taking the single quotes with password in usermod exec resource.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-04 01:53:07 -0500

updated 2016-04-04 04:05:29 -0500

It looks like you have a typo:

command => "usermod -p '$1$Sdqi/D28$DuBGUVe3h6b7z30csGGWN/';chage -d 0 thera"

should be

command => "usermod -p '$1$Sdqi/D28$DuBGUVe3h6b7z30csGGWN/' thera; chage -d 0 thera"

The second error is that the dollar signs ($) are being interpreted by Puppet as variables. Change it to:

command => 'usermod -p "\$1\$Sdqi/D28\$DuBGUVe3h6b7z30csGGWN/" thera; chage -d 0 thera'

That should work.

edit flag offensive delete link more


Thanks . I corrected the typo . But the issue is different now. I edited my original question to reflect this new issue

queszama gravatar imagequeszama ( 2016-04-04 02:15:48 -0500 )edit

I see, updated.

Alex Harvey gravatar imageAlex Harvey ( 2016-04-04 04:06:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-04-04 01:01:13 -0500

Seen: 161 times

Last updated: Apr 04 '16