alternate shadow file?

24 views
Skip to first unread message

eric.b....@nasa.gov

unread,
Jan 16, 2019, 12:00:19 PM1/16/19
to Ansible Project
Greetings.

I would like to use the "user" module to change my password, but the shadow file is not located in /etc/shadow .  It's in an alternate location, specifically, /mnt/pxe/etc/shadow .  Is there a way to accomplish this?

I have a bad feeling that the answer is "only if the underlying passwd command allows this option," which it doesn't.

I suppose the "lineinfile" module will accomplish this with a little bit of extra effort, but it would be nice if the standard "user" module would allow this.

Maybe somebody has a better idea?

Thanks.

--EbH

Brian Coca

unread,
Jan 16, 2019, 6:13:11 PM1/16/19
to Ansible Project
use chroot to /mnt/pxe and then use user module, passwd will then
'work as expected', with ansible this might mean using the 'chroot'
connection plugin


--
----------
Brian Coca

eric.b....@nasa.gov

unread,
Jan 17, 2019, 7:20:18 AM1/17/19
to Ansible Project
Unless the functionality has changed, it's my understanding that ansible cannot use chroot when managing a remote machine.

Hugo Gonzalez

unread,
Jan 17, 2019, 11:51:53 AM1/17/19
to ansible...@googlegroups.com

If there is a complete chroot environment under /mnt/pxe, you could configure a new ansible user to always log into a chrooted environment, using a sshd_config file and these two lines:

Match User new_ansible_user
ChrootDirectory /mnt/pxe

Then use ansible normally under that special user.

But that seems overkill, it would be easier to script the password change locally with mkpassword and some text manipulation.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e1b08699-09ab-4ae8-b8dc-7ebe3aef0bdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Hugo F. gonzalez

Senior Consultant

Red Hat LATAM

eric.b....@nasa.gov

unread,
Jan 22, 2019, 8:48:40 AM1/22/19
to Ansible Project
Thanks for the tip.  Setting up a chroot-only ansible-only user is a pretty good idea.

In this particular case, after talking with a co-worker, I ended up simply copying one shadow file to the other (note that this is a redacted copy for informational purposes only)

  tasks:
  - name: "update system password"
    user:
      name: "{{ item }}"
      update_password: always
  - name: "update chroot password"
    copy:
      src: /etc/shadow
      remote_src: yes
      dest: /mnt/pxe/etc/shadow
    notify: "rebuild image"

Reply all
Reply to author
Forward
0 new messages