Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible -B does not return ansible_job_id (page 37) #91

Closed
tliss opened this issue Apr 24, 2018 · 16 comments

Comments

@tliss
Copy link

commented Apr 24, 2018

This appears to be a long-standing issue with Ansible, as seen here:

ansible/ansible#15988

I commented on that thread with what I found, but I will copy+paste it here as well:

Attempting to do the ad-hoc command of:

ansible multi -b -B 3600 -a "yum -y update"

only returns:

192.168.60.4 | SUCCESS | rc=0 >>
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.den1.denvercolo.net
 * extras: mirrors.cat.pdx.edu
 * updates: mirrors.centos.webair.com
No packages marked for update

192.168.60.5 | SUCCESS | rc=0 >>
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nodesdirect.com
 * extras: repos.mia.quadranet.com
 * updates: mirror.atlantic.net
No packages marked for update

192.168.60.6 | SUCCESS | rc=0 >>
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.den1.denvercolo.net
 * extras: mirror.jax.hugeserver.com
 * updates: mirrors.centos.webair.com
No packages marked for update

when it should be returning something like:

background launch...
192.168.60.6 | success >> {
    "ansible_job_id": "763350539037",
    "results_file": "/root/.ansible_async/763350539037",
    "started": 1
}
... [other hosts] ...
@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Apr 24, 2018

Thanks for reporting this; I'll do a little digging.

@soulawaker

This comment has been minimized.

Copy link

commented May 23, 2018

Same here.

@wtnebel

This comment has been minimized.

Copy link

commented Jun 13, 2018

I'm seeing this as well.
Both with yum module and with the command supplied in the book.
Also, I'm not having luck testing this on other remote servers.
Do all Ad-Hoc commands support running in the background?

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 9, 2018

@wtnebel - They should... but they don't always.

I would recommend adding feedback to the upstream issue ansible/ansible#15988

@wtnebel

This comment has been minimized.

Copy link

commented Aug 9, 2018

Still waiting on a response for that one. Thanks Jeff!

Does anyone have an example set-up of it working correctly? I'm wondering if there's some issue with my specific versions/distributions of Ansible/Python/Host OS/Target OS.

@tliss

This comment has been minimized.

Copy link
Author

commented Aug 5, 2019

Looks like there is a change in the pipeline that will address this issue soon:

ansible/ansible#59935

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 20, 2019

Well... that was merged, and is in devel. I might get a chance to test it out soon...

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 20, 2019

Using Ansible 2.8.3:

$ ansible -i inventory multi -b -B 3600 -a "yum -y update"
 [WARNING]: Consider using the yum module rather than running 'yum'.  If you need to use command because yum is insufficient you can add 'warn:
false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.

192.168.60.4 | CHANGED | rc=0 >>
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.mobap.edu
 * extras: mirror.genesisadaptive.com
 * updates: mirror.mobap.edu
No packages marked for update

192.168.60.5 | CHANGED | rc=0 >>
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.fileplanet.com
 * extras: mirror.pit.teraswitch.com
 * updates: mirror.mobap.edu
No packages marked for update

192.168.60.6 | CHANGED | rc=0 >>
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.mobap.edu
 * extras: mirror.mobap.edu
 * updates: mirror.mobap.edu
No packages marked for update

Using latest devel:

$ ansible -i inventory multi -b -B 3600 -a "yum -y update"
 [WARNING]: Consider using the yum module rather than running 'yum'.  If you need to use command because yum is insufficient you can add 'warn:
false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.

192.168.60.5 | CHANGED => {
    "ansible_job_id": "169825235950.3572", 
    "changed": true, 
    "cmd": [
        "yum", 
        "-y", 
        "update"
    ], 
    "delta": "0:00:01.768099", 
    "end": "2019-08-20 21:43:14.836283", 
    "finished": 1, 
    "rc": 0, 
    "start": "2019-08-20 21:43:13.068184", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.fileplanet.com\n * extras: mirror.pit.teraswitch.com\n * updates: mirror.mobap.edu\nNo packages marked for update", 
    "stdout_lines": [
        "Loaded plugins: fastestmirror", 
        "Loading mirror speeds from cached hostfile", 
        " * base: mirror.fileplanet.com", 
        " * extras: mirror.pit.teraswitch.com", 
        " * updates: mirror.mobap.edu", 
        "No packages marked for update"
    ]
}
192.168.60.6 | CHANGED => {
    "ansible_job_id": "10147166642.3560", 
    "changed": true, 
    "cmd": [
        "yum", 
        "-y", 
        "update"
    ], 
    "delta": "0:00:01.690709", 
    "end": "2019-08-20 21:43:14.788515", 
    "finished": 1, 
    "rc": 0, 
    "start": "2019-08-20 21:43:13.097806", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.mobap.edu\n * extras: mirror.mobap.edu\n * updates: mirror.mobap.edu\nNo packages marked for update", 
    "stdout_lines": [
        "Loaded plugins: fastestmirror", 
        "Loading mirror speeds from cached hostfile", 
        " * base: mirror.mobap.edu", 
        " * extras: mirror.mobap.edu", 
        " * updates: mirror.mobap.edu", 
        "No packages marked for update"
    ]
}
192.168.60.4 | CHANGED => {
    "ansible_job_id": "379379275450.3575", 
    "changed": true, 
    "cmd": [
        "yum", 
        "-y", 
        "update"
    ], 
    "delta": "0:00:01.799457", 
    "end": "2019-08-20 21:43:14.877410", 
    "finished": 1, 
    "rc": 0, 
    "start": "2019-08-20 21:43:13.077953", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.mobap.edu\n * extras: mirror.genesisadaptive.com\n * updates: mirror.mobap.edu\nNo packages marked for update", 
    "stdout_lines": [
        "Loaded plugins: fastestmirror", 
        "Loading mirror speeds from cached hostfile", 
        " * base: mirror.mobap.edu", 
        " * extras: mirror.genesisadaptive.com", 
        " * updates: mirror.mobap.edu", 
        "No packages marked for update"
    ]
}
@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 20, 2019

Hmm... it seems polling doesn't work though—it waits until the very end and then gives all the job statuses. If I add -P 0 explicitly, it immediately dumps the ansible_job_id and everything. Strange behavior, maybe another bug?

At least the job IDs can be dumped if using -P 0 now.

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 20, 2019

To give more clarity:

ansible -i inventory multi -b -P 0 -B 3600 -m shell -a "while true; do echo test; sleep 5; done"

Ends up dumping:

192.168.60.4 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "ansible_job_id": "789829881512.4267", 
    "changed": true, 
    "finished": 0, 
    "results_file": "/root/.ansible_async/789829881512.4267", 
    "started": 1
}
...

But the following:

ansible -i inventory multi -b -B 3600 -m shell -a "while true; do echo test; sleep 5; done"

Sits forever. I would think it should poll every 10 seconds? If I add in -P 10, and wait over a minute, I still see no output.

The docs do indicate that polling should work like I'd expect... https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html#time-limited-background-operations

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 21, 2019

Tried with:

  • Ansible 2.9.0-devel (as of today): failed
  • Ansible 2.8.3: failed
  • Ansible 2.7.0: failed
  • Ansible 2.6.0: failed
  • Ansible 2.5.0: failed
  • Ansible 2.4.0: failed
  • Ansible 2.3.0: failed
  • Ansible 2.2.0: failed
  • Ansible 2.1.0: failed
  • Ansible 2.0.0: failed
  • Ansible 1.9.1: shows status immediately, then updates every 10 seconds

(Failed == there seemed to be no live polling)

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 21, 2019

Ansible 1.9.1 help:

  -P POLL_INTERVAL, --poll=POLL_INTERVAL
                        set the poll interval if using -B (default=15)

Ansible 2.8.4 help:

  -P POLL_INTERVAL, --poll=POLL_INTERVAL
                        set the poll interval if using -B (default=15)
@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 21, 2019

I opened an upstream issue: ansible/ansible#61015

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 21, 2019

Actual upstream issue to follow: ansible/ansible#14681

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 21, 2019

For now I'll update that section of the book to mention background tasks, but mention that polling does not work with realtime CLI output, so you can either run the task and it will complete and give final output and Job IDs, or run the task and immediately background it with -P 0 and it will give you the job IDs to check later.

@geerlingguy

This comment has been minimized.

Copy link
Owner

commented Aug 23, 2019

Closing this issue as the text will now default to presuming -P doesn't do anything unless set to -P 0 (in which case it immediately prints the job IDs and exits).

@geerlingguy geerlingguy referenced this issue Sep 4, 2019
24 of 24 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.