Files
ansible/modules-reference.md

1.4 KiB

Modules Reference

Commonly used Ansible modules:

Core Modules

  1. setup (Automatically collects system information):

    - name: Gather system facts
      ansible.builtin.setup:
    
  2. debug (For troubleshooting):

    - name: Show variable value
      ansible.builtin.debug:
        msg: "{{ some_variable }}"
    
  3. copy (For file transfer):

    - name: Copy file to remote host
      ansible.builtin.copy:
        src: "local_file.txt"
        dest: "/remote/path/"
    
  4. service (For service management):

    - name: Restart web service
      ansible.builtin.service:
        name: apache2
        state: restarted
    

Network Modules

  1. ping (Test connectivity):

    - name: Test connection to host
      ansible.builtin.ping:
    
  2. 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-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