use root to create admin user before disabling root ssh

25 views
Skip to first unread message

Brice Dorman

unread,
Mar 15, 2014, 3:31:04 PM3/15/14
to ansible...@googlegroups.com
objective:
I want to be able to run a single playbook on a host independent of what state its in and only change what's necessary.

problem:
One of the plays in my playbook installs a SW package that disables root ssh, so the first thing I do is create an admin user that can execute all plays, so when root ssh is disabled all the plays can still work.
However the next time this play is executed ( when the playbook is rerun ) the play fails because root ssh is disabled and therefore the playbook exits early.

---
- hosts: all
  user: root
  tasks:
    - name: Create an admin account user=cip
      user: name=cip password={{cip_password_hash}} shell=/bin/bash group={{admin_group}}

solutions:
What's the best "ansible" way to work around this issue?
1. Put this into a separate playbook and only execute once.
2. Remove the "user: root" from the play and add remote_user: root and ignore_errors: yes
3. Something I haven't thought of yet

Any advice would be greatly appreciated. Thanks in advance.

--Brice

Brian Coca

unread,
Mar 17, 2014, 11:27:51 AM3/17/14
to ansible...@googlegroups.com
have a 'pre play' that just has 3 tasks, 1st one tries to login as root, that play on failure sets_fact ansible_ssh_user per host to either root (on success) or newadmin (on failure).


--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno
Reply all
Reply to author
Forward
0 new messages