Reputation: 564
I need to gather facts when executing my playbook. But the hosts have not installed Python yet.
If I gather facts first, the playbook will raise error because of lacking Python. If I install Python first, I have to set gather_facts
to no
.
How to gather facts after installing Python in one Ansible playbook?
Here is my playbook:
---
- hosts: all
gather_facts: yes
pre_tasks:
- name: Install Python 2.x
raw: test -e /usr/bin/python || (apt update && apt install -y python-simplejson)
tasks:
...
Upvotes: 0
Views: 1015
Reputation: 1954
Use setup
module.
---
- hosts: all
gather_facts: no
pre_tasks:
- name: Install Python 2.x
raw: test -e /usr/bin/python || (apt update && apt install -y python-simplejson)
tasks:
- name: Get facts
setup:
- name: Other tasks.....
....
Documentation: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html
Upvotes: 2