# Bootstrapping a server: changing ansible\_host and ansible\_user idempotently in a single playbook

**URL:** <https://forum.ansible.com/t/bootstrapping-a-server-changing-ansible-host-and-ansible-user-idempotently-in-a-single-playbook/46849>\
**Category:** Get Help\
**Tags:** ssh, playbook, inventory, ansible-core\
**Created:** [November 30, 2026, 4:49am UTC](https://forum.ansible.com/t/bootstrapping-a-server-changing-ansible-host-and-ansible-user-idempotently-in-a-single-playbook/46849 "2026-11-30T04:49:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Requord](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@Requord](https://forum.ansible.com/u/Requord)\
**Post date:** [November 30, 2026, 4:49am UTC](https://forum.ansible.com/t/bootstrapping-a-server-changing-ansible-host-and-ansible-user-idempotently-in-a-single-playbook/46849/1 "2026-11-30T04:49:27Z")

</div>

Let me first say: apologies, my question feels so general and I’m so new that I’m not sure which tags belong to it, and I’ve spend a bunch of time between AI and index searching that I still don’t really know the answers to my concern.

I’m trying to figure out what would be the ideal or conventional way to bootstrap a server such that a single playbook and inventory can be used with idempotence to do two things that change inventory attributes:

1. ansible\_user: Root login with password at first, swap to key-only and create deploy user.
2. ansible\_host: Put up Wireguard, shift sshd to only listen to it–future connections use the Wireguard IP

I could, of course, manually change each of these and use different playbooks for stages. However, correct me if I’m wrong, but that doesn’t seem to me as though I would be leveraging Ansible fully.

I’m under the impression that a single playbook should be able to be run repeatedly for a given server from first run and any following changes; is that how things are conventionally done?

I’ve considered automating via roles in a playbook, but I’d really want to attach root/deploy users and wireguard, private/public (or both) IPs to a single host at the inventory level.  
I’ve also considered using multiple entries in inventory, but that somewhat breaks my idea of the spirit of idempotence and if I had, say fail2ban aggressively enabled and hit, say port 22 when it is set to block any IP trying to reach it there, well… it just seems as though there’s probably better logic set up as–at least to me–I feel there must be already well established conventions to handle such a situation–at least with bootstrapping from root to a deploy user, right?

---

<div class="post-metadata">

**Author:** ![Rei\_Kurosawa](https://avatars.discourse-cdn.com/v4/letter/r/e5b9ba/32.png) [@Rei\_Kurosawa](https://forum.ansible.com/u/Rei_Kurosawa)\
**Post date:** [November 30, 2026, 7:24am UTC](https://forum.ansible.com/t/bootstrapping-a-server-changing-ansible-host-and-ansible-user-idempotently-in-a-single-playbook/46849/2 "2026-11-30T07:24:55Z")

</div>

Yes, a single playbook with one inventory entry per server is a conventional shape: the playbook changes its own connection settings between plays instead of the inventory changing. A first play can log in as root (play-level `remote_user`, the user used to log into the target via the connection plugin), create the deploy user and install its key; later plays set `ansible_user` to that deploy user. When WireGuard is up, update the host in the in-memory inventory with `add_host`, setting `ansible_host` to the tunnel address, then call `meta: reset_connection`, which interrupts the persistent connection so the following tasks reconnect with the new user and address. Keeping each task declarative (user exists, key installed, sshd listens only on the tunnel interface) is what keeps the playbook rerunnable from first boot onward. For tasks that still need root after the switch, use `become` on those tasks rather than keeping root SSH login.  
Assisted-by: AI.
