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