use facts from another task

20 views
Skip to first unread message

Marc Haber

unread,
May 22, 2019, 11:55:48 AM5/22/19
to ansible...@googlegroups.com
Hi,

here is my site.yml:

---
- name: apply common configuration
hosts: all
remote_user: zgansible
become: "yes"
tasks:
- name: get package facts
package_facts:
manager: "auto"
- import_role:
name: mlocate
when: ansible_facts.packages["mlocate"] is defined

That one doesn't work:
fatal: [emptysid86]: FAILED! => {"msg":
"The conditional check 'ansible_facts.packages[\"mlocate\"]
is defined' failed.
The error was: error while evaluating conditional
(ansible_facts.packages[\"mlocate\"] is defined):
'dict object' has no attribute 'packages'
The error appears to have been in '/home/mh/git/zgdebansible/roles/mlocate/tasks/main.yml':
line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:- name:create symlinks for mlocate
^ here
"}

The alternative, writing the when clause into all tasks in the role,
clutters up the roles and makes them unportable. Also, I need to have
all my roles depend on package_facts, which for some weird reason causes
the package_facts role to be re-executed over and over and over again
which takes ages.

How would I make the ansible_facts.packages dictionary universally
availabe while only collecting the list of installed packages once?

Greetings
Marc

--
-----------------------------------------------------------------------------
Marc Haber | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

Marc Haber

unread,
May 25, 2019, 2:27:59 PM5/25/19
to ansible...@googlegroups.com
On Wed, May 22, 2019 at 05:55:39PM +0200, Marc Haber wrote:
> How would I make the ansible_facts.packages dictionary universally
> availabe while only collecting the list of installed packages once?

Solved, I had my tags wrong. Learned about the "always" Tag, which is
really nice.
Reply all
Reply to author
Forward
0 new messages