# Get IP address facts after configuring DHCP

**URL:** <https://forum.ansible.com/t/get-ip-address-facts-after-configuring-dhcp/13544>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [September 24, 2013, 11:13pm UTC](https://forum.ansible.com/t/get-ip-address-facts-after-configuring-dhcp/13544 "2013-09-24T23:13:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kent\_R\_Spillner](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@Kent\_R\_Spillner](https://forum.ansible.com/u/Kent_R_Spillner)\
**Post date:** [September 24, 2013, 11:13pm UTC](https://forum.ansible.com/t/get-ip-address-facts-after-configuring-dhcp/13544/1 "2013-09-24T23:13:09Z")

</div>

Does anyone have a good method of getting the IP address leased to an interface in the middle of a play?

I have some RHEL 6 servers that use DHCP. I want to configure source-based routing on each so I need to know the actual IP address acquired by the DHCP lease. i.e. my playbook ensures BOOTPROTO=dhcp in /etc/sysconfig/network-scripts/ifcfg-{{ interface }}, then writes /etc/sysconfig/network-scripts/rule-{{ interface}} from the template:

unicast from {{ ip\_address }} table {{ interface }}

A couple of ways I thought about doing it include:

\* Run twice. The first time the interface is configured to use DHCP and brought up, and then the second time I can pull the IP address from ansible\_facts. That kind of sucks, but it works.

\* Create a handler that re-runs the setup module to get the facts about the new interface, have the interface config action notify that handler, and then call flush\_handlers. That works and avoids having to run the playbook twice, but it would be better if I could only flush the one handler (I might not actually want to flush ALL handlers everytime). Is flush\_handlers parameterized? I haven't checked the code yet...

\* I could skip the handler & flush\_handles and just insert an action that always calls the setup module. That avoids potentially flushing handlers I don't want to flush at the expense of having to document & remember why it's important that action "always must come after the interface configuration and before the rule & routes configuration"

Are there any other alternatives? Is there a best way? All advice greatly appreciated! 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 25, 2013, 12:47am UTC](https://forum.ansible.com/t/get-ip-address-facts-after-configuring-dhcp/13544/2 "2013-09-25T00:47:20Z")

</div>

I’d just do:

- setup

after the other step.
