Luv33preet
Luv33preet

Reputation: 1867

Async tasks in Ansible

I have a question about the working of async tasks in ansible.

Suppose, I open 2 terminals, and run sudo apt-get update on both. Obviously, it will not run on both due to the lock file.

luvpreet@DHARI-Inspiron-3542:/etc/ansible$ sudo apt-get update
Reading package lists... Done
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

Now, on ansible, I did this,

- name: update cache
  apt:
    update_cache: yes
  async: 1
  poll: 0

- name: update cache
  apt:
    update_cache: yes
  async: 1
  poll: 0

Now, the role containing these 2 consecutive tasks should never be completed as ansible cannot run 2 update tasks simultaneously.

But still it did, and did not threw any error. Why is it so ?

Upvotes: 2

Views: 12213

Answers (1)

Hgfjj Hhjgf
Hgfjj Hhjgf

Reputation: 29

As you have used poll: 0, ie: fire-and-forget, for just 1 second, as specified in async: 1, your shell terminal session is active for just one second, that is after the very first second of running updating command at the remote node, it will be terminated and thus giving the second task a chance to do the same for the next 1second releasing the lock from

/var/lib/apt/list/lock

I hope this explains the scenerio :)

Upvotes: 1

Related Questions