Ansible role with a reboot fails

74 views
Skip to first unread message

ZillaYT

unread,
Apr 17, 2018, 2:47:13 PM4/17/18
to Ansible Project
I've trying to write an Ansible role that upgrades Github. The command to upgrade the server "ghe-upgrade github-2.13.1.pkg" for example, reboots the server, and when that happens, I get, the following connection because my ssh connection drops of course.

TASK [github : Upgrade github1.company.com with version 2.13.1] **********
fatal: [github1.company.com]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ", "unreachable": true}
        to retry, use: --limit @/build/workspace/team_SCSCM/github/github-upgrade.retry


I tried the ideas from ansible-reboot-and-wait.yml exmaple, and others with similar approach, to no avail. So my tasks look like

# This command will reboot the node
- name: Upgrade Github host
  command: "ghe-upgrade {{ pkg_dir }}/{{ pkg_name }} --yes"

(It craps out after above task)

# Now we will run a local 'ansible -m ping' on this host until it returns.
# This works with the existing ansible hosts inventory and so any custom ansible_ssh_hosts definitions are being used
- local_action: shell ansible -u {{ ansible_ssh_user }} -m ping github1.company.com
  register: result
  until: result.rc == 0
  retries: 30
  delay: 10


Any pointers on how I can make this work? Thanks!
Message has been deleted

John Harmon

unread,
Apr 17, 2018, 4:28:22 PM4/17/18
to Ansible Project
Sorry, ignore my last post..... I can see that is exactly what you did

Kai Stian Olstad

unread,
Apr 17, 2018, 5:11:43 PM4/17/18
to ansible...@googlegroups.com
On 17.04.2018 20:47, ZillaYT wrote:
> I tried the ideas from ansible-reboot-and-wait.yml exmaple
> <https://gist.github.com/infernix/a968f23c4f4e1d6723e4>, and others
> with

That's over 4 years old, in this profession that is a lifetime.


> similar approach, to no avail. So my tasks look like
>
> # This command will reboot the node
> - name: Upgrade Github host
> command: "ghe-upgrade {{ pkg_dir }}/{{ pkg_name }} --yes"
>
> (It craps out after above task)
>
> # Now we will run a local 'ansible -m ping' on this host until it
> returns.
> # This works with the existing ansible hosts inventory and so any
> custom
> ansible_ssh_hosts definitions are being used
> - local_action: shell ansible -u {{ ansible_ssh_user }} -m ping
> github1.company.com
> register: result
> until: result.rc == 0
> retries: 30
> delay: 10
>
>
> Any pointers on how I can make this work? Thanks!

If it's possible to make ghe-upgrade not reboot the server that would be
easiest I guess.
The reason is you don't not how long the upgrade process will take and
make it hard to find a value for the delay bellow.

The reboot is as simple as

- name: reboot server
shell: sleep 2 && reboot
async: 1
poll: 0

- name: Wait for server
wait_for_connection:
delay: 60

The delay must be at least as long it takes for the server to shutdown
ssh, it not it will be able to connect again and the play continues.

--
Kai Stian Olstad

Karl Auer

unread,
Apr 17, 2018, 7:16:48 PM4/17/18
to ansible...@googlegroups.com
Not quite exactly - there was no pause task in the OP's version.

The linked webpage says that the pause is needed to prevent the existing control connection being used.

Regards, K.


--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/64f1150b-8261-400b-9437-dddc8cb47980%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Karl Auer

Email  : ka...@2pisoftware.com
Website: 
http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

ZillaYT

unread,
Apr 18, 2018, 9:08:40 AM4/18/18
to Ansible Project
Thanks all. Yes there should've been a pause between the two tasks. And yes there is an option to not reboot during the ghe-upgrade procedure, but I still would need to reboot twice after the command, once for Github to finish its upgrade, and another for the upgrade to take effect. So I still would to use the tricks mentioned here.
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.
Reply all
Reply to author
Forward
0 new messages