0% found this document useful (0 votes)
23 views8 pages

Ansible Modules Guide

The document provides an overview of common Ansible modules categorized into file management, user and group management, service management, package management, network modules, file system management, time and date modules, command and shell execution, system info modules, and debugging modules. Each category includes specific modules with their purposes and examples of usage. This serves as a reference for users to understand and utilize various Ansible modules effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views8 pages

Ansible Modules Guide

The document provides an overview of common Ansible modules categorized into file management, user and group management, service management, package management, network modules, file system management, time and date modules, command and shell execution, system info modules, and debugging modules. Each category includes specific modules with their purposes and examples of usage. This serves as a reference for users to understand and utilize various Ansible modules effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Common Ansible Modules

1. File Management Modules:

a. file

- Purpose: Manages file properties (permissions, ownership, etc.)

Example:

- name: Set permissions on a file

file:

path: /tmp/hello.txt

owner: root

group: root

mode: '0644'

state: touch

b. copy

- Purpose: Copies a file or directory from the local machine to the target machine.

Example:

- name: Copy a local file to remote machine

copy:

src: /local/file.txt

dest: /remote/file.txt

c. template

- Purpose: Renders a Jinja2 template and copies it to a remote machine.


Example:

- name: Deploy configuration file from template

template:

src: /templates/nginx.conf.j2

dest: /etc/nginx/nginx.conf

d. fetch

- Purpose: Fetches a file from a remote machine to the local machine.

Example:

- name: Fetch a file from remote machine

fetch:

src: /remote/path/to/file.txt

dest: /local/path/to/file.txt

2. User and Group Management Modules:

a. user

- Purpose: Manages user accounts.

Example:

- name: Create a new user

user:

name: alice

state: present

shell: /bin/bash

b. group
- Purpose: Manages groups.

Example:

- name: Add a new group

group:

name: devs

state: present

3. Service Management Modules:

a. service

- Purpose: Manages services (start, stop, restart).

Example:

- name: Ensure nginx is running

service:

name: nginx

state: started

enabled: yes

b. systemd

- Purpose: Manage systemd services on Linux systems.

Example:

- name: Restart nginx using systemd

systemd:

name: nginx

state: restarted
4. Package Management Modules:

a. apt

- Purpose: Manages packages using apt (for Debian/Ubuntu-based systems).

Example:

- name: Install nginx using apt

apt:

name: nginx

state: present

b. yum

- Purpose: Manages packages using yum (for RedHat/CentOS systems).

Example:

- name: Install nginx using yum

yum:

name: nginx

state: present

c. pip

- Purpose: Manages Python packages using pip.

Example:

- name: Install a Python package

pip:

name: requests

state: present
5. Network Modules:

a. ping

- Purpose: Simple module to check if the target is reachable.

Example:

- name: Ping the target machine

ping:

b. uri

- Purpose: Interact with HTTP/HTTPS-based services (e.g., sending HTTP requests).

Example:

- name: Make a GET request to an API

uri:

url: "https://api.example.com/data"

method: GET

return_content: yes

6. File System Management:

a. mount

- Purpose: Manages mount points (e.g., mount a disk or network share).

Example:

- name: Mount a filesystem

mount:

path: /mnt/data

src: /dev/sdb1
fstype: ext4

state: mounted

b. archive

- Purpose: Creates or extracts archive files (tar, zip, etc.).

Example:

- name: Create a tar archive

archive:

path: /tmp/data

dest: /tmp/data.tar.gz

format: gz

7. Time and Date Modules:

a. cron

- Purpose: Manages cron jobs.

Example:

- name: Schedule a cron job

cron:

name: "Backup script"

minute: "0"

hour: "2"

job: "/usr/bin/backup.sh"

8. Command and Shell Execution Modules:


a. command

- Purpose: Executes a command on the remote machine.

Example:

- name: Run a command

command: /usr/bin/uptime

b. shell

- Purpose: Executes a shell command (supports shell features like pipes, redirects).

Example:

- name: Run a shell command

shell: echo "Hello World" > /tmp/hello.txt

9. System Info Modules:

a. setup

- Purpose: Gathers system facts and returns details about the machine (OS, IP, memory, etc.).

Example:

- name: Gather system facts

setup:

10. Debugging and Output Modules:

a. debug

- Purpose: Displays debug information (prints variables, messages, etc.).

Example:

- name: Debug the value of a variable


debug:

msg: "The value of my_variable is {{ my_variable }}"

You might also like