What are common Ansible modules?

056

Common Ansible modules include:

  1. command: Executes a command on a remote host.

    - name: Run a command
      command: /path/to/command
  2. shell: Executes a shell command on a remote host.

    - name: Run a shell command
      shell: echo "Hello, World!"
  3. copy: Copies files from the control machine to the remote host.

    - name: Copy a file
      copy:
        src: /local/path/to/file
        dest: /remote/path/to/file
  4. file: Manages file properties (e.g., permissions, ownership).

    - name: Set file permissions
      file:
        path: /path/to/file
        mode: '0644'
  5. template: Renders a Jinja2 template and copies it to the remote host.

    - name: Deploy a configuration file
      template:
        src: template.j2
        dest: /etc/config.conf
  6. yum: Manages packages using the YUM package manager (for Red Hat-based systems).

    - name: Install a package
      yum:
        name: httpd
        state: present
  7. apt: Manages packages using the APT package manager (for Debian-based systems).

    - name: Install a package
      apt:
        name: apache2
        state: present
  8. service: Manages services (start, stop, restart).

    - name: Ensure a service is running
      service:
        name: httpd
        state: started
  9. user: Manages user accounts on the remote host.

    - name: Create a user
      user:
        name: newuser
        state: present
  10. git: Manages Git repositories.

    - name: Clone a Git repository
      git:
        repo: 'https://github.com/user/repo.git'
        dest: /path/to/destination

These modules cover a wide range of tasks, from file management to package installation and service management, making them essential for automating IT tasks with Ansible.

0 Comments

no data
Be the first to share your comment!