# bootstrapping nodes - when the setup module fails

**URL:** <https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340>\
**Category:** Ansible Project\
**Created:** [January 14, 2014, 3:01pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340 "2014-01-14T15:01:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Cottlehuber](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Dave\_Cottlehuber](https://forum.ansible.com/u/Dave_Cottlehuber)\
**Post date:** [January 14, 2014, 3:01pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/1 "2014-01-14T15:01:19Z")

</div>

Hi,

Is it possible to handle the initial ssh connection failure rather than bail out completely? Let me clarify why, maybe there’s a better way to do this.

I’ve got a wide variety of OS & cloud providers to test stuff against, and I’m slowly automating all of this. Bootstrapping in this case comprises ensuring we have a suitable python, adding root & ansible user ssh keys, sudo etc before normal ansible work. Currently I have a separate bootstrap script to get nodes off the ground, but what I really want is single `site.yml` to handle that as well.

I thought I could use the setup module to check if we need to bootstrap or not:

```site.yml

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 14, 2014, 3:21pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/2 "2014-01-14T15:21:47Z")

</div>

Take a look at this ec2 example: [http://docs.ansible.com/guide\_aws.html#example-4](http://docs.ansible.com/guide_aws.html#example-4)

The wait\_for module is capable of delaying a play until some resource (ssh for example) becomes available.

---

<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:** [January 14, 2014, 3:24pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/3 "2014-01-14T15:24:52Z")

</div>

Well, sort of. That waits for a port to become available, not trying to see if a username/password can already log in.

There’s nothing available to try a lot of random access credentials to see what works.

I’d recommend hosts get bootstrapped via a basic kickstart/preseed in most cases, but that’s just me.

---

<div class="post-metadata">

**Author:** ![Dave\_Cottlehuber](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Dave\_Cottlehuber](https://forum.ansible.com/u/Dave_Cottlehuber)\
**Post date:** [January 14, 2014, 11:59pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/4 "2014-01-14T23:59:46Z")

</div>

Thanks, I accept I need 2 separate playbooks for this ☹

I've found however that `gather_facts=False` in the top-level playbook  
doesn't seem to get propagated through to an individual role, and  
AFAICT it's not possible to set that flag at a role level. So net  
result is that it's not possible to disable fact-gathering in a  
complex setup. The same declarations run just fine in a single  
playbook.

See in line 34 of the playbook+role log, ansible insists on running  
the setup module, and obviously fails as python is not yet present:  
[https://www.irccloud.com/pastebin/q3Ht1Llw](https://www.irccloud.com/pastebin/q3Ht1Llw)

The same in a single playbook runs fine:  
[https://www.irccloud.com/pastebin/RpjehH2Y](https://www.irccloud.com/pastebin/RpjehH2Y)

Is this a bug, or expected behaviour?

---

<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:** [January 15, 2014, 12:11am UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/5 "2014-01-15T00:11:24Z")

</div>

“I’ve found however that `gather_facts=False` in the top-level playbook  
doesn’t seem to get propagated through to an individual role,”

False.

Fact gathering runs before roles.

“AFAICT it’s not possible to set that flag at a role level.”

Because it’s a property of the playbook, yes. Also it doesn’t matter because the default is to gather facts, which is what you want 99.99% of the time. If you don’t, it just makes you wait a tiny bit. You enable or disable this at play level.

“So net  
result is that it’s not possible to disable fact-gathering in a  
complex setup”

False.

Now what you’ve pasted doesn’t really match my expectation of reality, so perhaps you have copy/pasted provisioning.yml or something?

You can totally do “gather\_facts: false”.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 15, 2014, 12:55am UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/6 "2014-01-15T00:55:35Z")

</div>

> TASK: [bootstrap | setup]

This seems to indicate you have an explicit call to the setup module inside  
the bootstrap role.

I have a simple bootstrap play I've used with FreeBSD, disabling  
gather\_facts: is all you need to use raw to install python with simplejson.

FYI, roles DON'T automatically gather facts, plays do, roles run tasks,  
only if you create a explicit task that gathers facts will a role gather  
them.

---

<div class="post-metadata">

**Author:** ![Dave\_Cottlehuber](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Dave\_Cottlehuber](https://forum.ansible.com/u/Dave_Cottlehuber)\
**Post date:** [January 15, 2014, 2:29pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/7 "2014-01-15T14:29:53Z")

</div>

^^ bingo ^^

Aha… thanks both Brian & Michael very much.

I was completely mistaken about how tasks in roles are processed;  
there's a roles/bootstrap/main.yml with a setup call in it, which as  
per documentation is pulled in.

Sorry for the noise!

A+  
Dave

---

<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:** [January 15, 2014, 2:30pm UTC](https://forum.ansible.com/t/bootstrapping-nodes-when-the-setup-module-fails/14340/8 "2014-01-15T14:30:30Z")

</div>

Nice catch Brian!
