ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Jenkins + Ansible Playbook 사용
    CI-CD 2023. 2. 16. 13:31

    1. Item 추가 -> My-Ansible-Project

     - Copy from : My-Docker-Project

     

    2. 기존 설정 변경 및 삭제

     2.1 Post-build Action

       - Deploy war/ear to a container -> Delete

       - Send build artifacts over SSH

         - SSH Server

             - Name: [Publis over SSH에서 설정한 이름] ex) ansible-host

             - Transfer Set

                  - Source files: target/*.war

                  - Remove prefix: target

                  - Remote directory: .

                  - Exec command : ansible-playbook -i hosts first-devops-playbook.yml

       - Save > Build Now

     

    3. Create an ansible playbook file

      - $ vi first-devops-playbook.yml

    - hosts: all
    #   become: true  

      tasks:
      - name: stop current runnning container
        command: docker stop my_cicd_project
     
      - name: remove stopped container
        command: docker rm my_cicd_project

      - name: remove current docker image
        command: docker rmi cicd-project-ansible

      - name: build a docker image with deployed war file
        command: docker build -t cicd-project-ansible .
        args: 
            chdir: /root

      - name: create a container using cicd-project-ansible image
        command: docker run -d --name my_cicd_project -p 8080:8080 cicd-project-ansible
      

    4. Create a hosts file

      - $ vi hosts

      - etc/hosts말고 따로 호스트파일 지정하려면 ansible-playbook 명령어 사용시 -i hosts 명령어 필수

     

     

    'CI-CD' 카테고리의 다른 글

    Kubernetes 설치  (0) 2023.02.17
    Kubernetes 소개  (0) 2023.02.17
    Jenkins + Ansible 연동  (0) 2023.02.16
    Ansible Playbook 사용하기  (0) 2023.02.14
    Ansible 기본 명령어 및 모듈사용  (0) 2023.02.14
Designed by Tistory.