Fabric is usually installed on a deployment/control node and used to orchestrate remote hosts over SSH.
- name: Install Fabric on Debian family
hosts: fabric_debian
become: true
vars:
fabric_user: deploy
fabric_home: /opt/fabric
tasks:
- name: Install dependencies
ansible.builtin.apt:
update_cache: true
name:
- python3
- python3-venv
- python3-pip
- git
- openssh-client
state: present
- name: Ensure Fabric user exists
ansible.builtin.user:
name: "{{ fabric_user }}"
shell: /bin/bash
create_home: true
- name: Create Fabric workspace
ansible.builtin.file:
path: "{{ fabric_home }}"
state: directory
owner: "{{ fabric_user }}"
group: "{{ fabric_user }}"
mode: "0755"
- name: Create virtual environment
ansible.builtin.command: python3 -m venv {{ fabric_home }}/venv
args:
creates: "{{ fabric_home }}/venv/bin/activate"
- name: Install Fabric package
ansible.builtin.pip:
name: fabric
virtualenv: "{{ fabric_home }}/venv"
- name: Verify Fabric installation
ansible.builtin.command: "{{ fabric_home }}/venv/bin/fab --version"
changed_when: false
- name: Install Fabric on RHEL family
hosts: fabric_rhel
become: true
vars:
fabric_user: deploy
fabric_home: /opt/fabric
tasks:
- name: Install dependencies
ansible.builtin.dnf:
name:
- python3
- python3-pip
- python3-virtualenv
- git
- openssh-clients
state: present
- name: Ensure Fabric user exists
ansible.builtin.user:
name: "{{ fabric_user }}"
shell: /bin/bash
create_home: true
- name: Create Fabric workspace
ansible.builtin.file:
path: "{{ fabric_home }}"
state: directory
owner: "{{ fabric_user }}"
group: "{{ fabric_user }}"
mode: "0755"
- name: Create virtual environment
ansible.builtin.command: python3 -m venv {{ fabric_home }}/venv
args:
creates: "{{ fabric_home }}/venv/bin/activate"
- name: Install Fabric package
ansible.builtin.pip:
name: fabric
virtualenv: "{{ fabric_home }}/venv"
- name: Verify Fabric installation
ansible.builtin.command: "{{ fabric_home }}/venv/bin/fab --version"
changed_when: false
ansible-playbook -i inventory.ini fabric-install.yml
fabric_debian.fabfile.py inventory logic.