Junior — Middle
How to automate Python installation on a remote server using Ansible?
sobes.tech AI
Answer from AI
To automate the installation of Python on a remote server using Ansible, you can use the apt module (for Debian/Ubuntu) or yum (for CentOS/RHEL). The playbook specifies tasks for updating the package cache and installing the desired Python version.
Example of a simple playbook for Ubuntu:
- hosts: servers
become: yes
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install Python 3
apt:
name: python3
state: present
If a specific Python version or installation from source is needed, additional tasks can be added. You can also use the geerlingguy.python role from Ansible Galaxy for more complex scenarios.