63 lines
1.4 KiB
Markdown
63 lines
1.4 KiB
Markdown
## Modules Reference
|
|
|
|
Commonly used Ansible modules:
|
|
|
|
### Core Modules
|
|
|
|
1. **setup** (Automatically collects system information):
|
|
```yaml
|
|
- name: Gather system facts
|
|
ansible.builtin.setup:
|
|
```
|
|
|
|
2. **debug** (For troubleshooting):
|
|
```yaml
|
|
- name: Show variable value
|
|
ansible.builtin.debug:
|
|
msg: "{{ some_variable }}"
|
|
```
|
|
|
|
3. **copy** (For file transfer):
|
|
```yaml
|
|
- name: Copy file to remote host
|
|
ansible.builtin.copy:
|
|
src: "local_file.txt"
|
|
dest: "/remote/path/"
|
|
```
|
|
|
|
4. **service** (For service management):
|
|
```yaml
|
|
- name: Restart web service
|
|
ansible.builtin.service:
|
|
name: apache2
|
|
state: restarted
|
|
```
|
|
|
|
### Network Modules
|
|
|
|
5. **ping** (Test connectivity):
|
|
```yaml
|
|
- name: Test connection to host
|
|
ansible.builtin.ping:
|
|
```
|
|
|
|
6. **sshcopy** (Copy files via SSH):
|
|
```yaml
|
|
- name: Copy file using SSH
|
|
ansible.builtin.sshcopy:
|
|
src: "local_file.txt"
|
|
dest: "user@host:/remote/path/"
|
|
```
|
|
|
|
### Best Practices
|
|
|
|
- Use `ansible-doc` to view module details
|
|
- Combine with `when` conditions for targeted execution
|
|
- Use `--check` flag to simulate module operations
|
|
- Store sensitive data using Ansible Vault
|
|
|
|
### Troubleshooting
|
|
|
|
- Use `--verbosity=2` for detailed output
|
|
- Check module documentation for parameter requirements
|
|
- Use `ansible-playbook --list-tasks` to verify task execution order |