Logo

Personal Ops Runbook

Personal runbook covering infrastructure operations for Cloud, Kubernetes, OpenStack, and Ceph environments. Includes deployment and teardown procedures, node management, cluster monitoring setup, and incident response workflows compiled from day-to-day operational work. Intended strictly for personal reference — configurations and scripts are environment-specific and not guaranteed to work as-is elsewhere.

[Ansible] Sử dụng Ansible để tải xuống mã nguồn từ GitLab


Để sử dụng Ansible để tải xuống mã nguồn từ GitLab, khi một kho lưu trữ của GitLab đang trong chế độ riêng tư và yêu cầu xác thực, bạn có thể cung cấp tên người dùng và mật khẩu bằng các biến môi trường GITLAB_USERGITLAB_PASSWORD trong quá trình chạy Ansible playbook.

Ví dụ, playbook sau đây sử dụng module git để tải xuống mã nguồn từ một kho lưu trữ của GitLab:

- name: Download source code from GitLab
  hosts: localhost
  tasks:
    - name: Set GitLab credentials
      environment:
        GITLAB_USER: "your_gitlab_username"
        GITLAB_PASSWORD: "your_gitlab_password"
      become: false

    - name: Clone repository
      git:
        repo: "https://gitlab.com/your_gitlab_username/your_gitlab_project.git"
        dest: "/path/to/destination"
      become: false

Trong playbook này, ta sử dụng module environment để cung cấp biến môi trường GITLAB_USERGITLAB_PASSWORD cho quá trình chạy playbook. Sau đó, ta sử dụng module git để tải xuống mã nguồn từ kho lưu trữ của GitLab với URL https://gitlab.com/your_gitlab_username/your_gitlab_project.git.

Lưu ý rằng, trong thực tế, việc lưu trữ tên người dùng và mật khẩu trong file playbook là không an toàn, do đó bạn nên sử dụng các biến môi trường được đặt trong môi trường thực thi. Ngoài ra, bạn cũng có thể sử dụng công cụ quản lý mật khẩu như Ansible Vault để bảo vệ các thông tin nhạy cảm trong quá trình chạy playbook.