Ansible Modules Guide
Ansible Modules Guide
a. file
Example:
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:
copy:
src: /local/file.txt
dest: /remote/file.txt
c. template
template:
src: /templates/nginx.conf.j2
dest: /etc/nginx/nginx.conf
d. fetch
Example:
fetch:
src: /remote/path/to/file.txt
dest: /local/path/to/file.txt
a. user
Example:
user:
name: alice
state: present
shell: /bin/bash
b. group
- Purpose: Manages groups.
Example:
group:
name: devs
state: present
a. service
Example:
service:
name: nginx
state: started
enabled: yes
b. systemd
Example:
systemd:
name: nginx
state: restarted
4. Package Management Modules:
a. apt
Example:
apt:
name: nginx
state: present
b. yum
Example:
yum:
name: nginx
state: present
c. pip
Example:
pip:
name: requests
state: present
5. Network Modules:
a. ping
Example:
ping:
b. uri
Example:
uri:
url: "https://api.example.com/data"
method: GET
return_content: yes
a. mount
Example:
mount:
path: /mnt/data
src: /dev/sdb1
fstype: ext4
state: mounted
b. archive
Example:
archive:
path: /tmp/data
dest: /tmp/data.tar.gz
format: gz
a. cron
Example:
cron:
minute: "0"
hour: "2"
job: "/usr/bin/backup.sh"
Example:
command: /usr/bin/uptime
b. shell
- Purpose: Executes a shell command (supports shell features like pipes, redirects).
Example:
a. setup
- Purpose: Gathers system facts and returns details about the machine (OS, IP, memory, etc.).
Example:
setup:
a. debug
Example: