본문 바로가기

Playbook

(13)
8.5 ansible | [playbook] docker 설치 # docker-ce-20.10.5 --- - hosts: all become: yes tasks: - name: "yum install packages" yum: name: "{{ item }}" state: installed loop: - epel-release - yum-utils - git - name: "docker repo add" command: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo - name: "docker install" yum: name: "{{ item }}" state: installed loop: - docker-ce-20.10.5 - python3 - python..
8.4 ansible | [playbook] nodejs, npm 설치 ## nodejs 14.15.4, npm 6.14.10 --- - name: "NPM, NODEJS INSTALL" become: true hosts : all gather_facts: no tasks: - name: "install wget" yum: name: wget state: installed - name: "repo download" get_url: url: https://rpm.nodesource.com/setup_lts.x dest: /tmp/node_setup.sh - name: "repo install" shell: /bin/bash /tmp/node_setup.sh - name: "install nodejs" yum: name: "{{ item }}" state: installed l..
8.3 ansible | [playbook] centos6 yum repository 변경 centos6의 공식 repository가 만료되어 아래와 같이 주소 변경. --- - name: "Modify CentOS6 Base Repo" hosts: all become: true tasks: - name: "Modify CentOS6 Base Repo" replace: path: /etc/yum.repos.d/CentOS-Base.repo regexp: "{{ item.origin }}" replace: "{{ item.replace }}" with_items: - { origin: "mirrorlist=http://mirrorlist.centos.org", replace: "#mirrorlist=http://mirrorlist.centos.org" } - { origin: "#baseurl=..
8.2 ansible | [playbook] Linux service 상태 변경 --- - name: "Change Service State " hosts: all become: true tasks: - name: "Change Service State " service: name: "{{ service_name }}" # state : reloaded|restarted|started|stopped state: "{{ service_state }}" # enabled : yes|no enabled: "{{ service_enable }}" # 조건 : centos 6 or 7 인 경우만 when: - ansible_facts['distribution'] == "CentOS" - ( ansible_facts['distribution_major_version'] == "6" or ans..
1.9 ansible | [test][playbook] docker container start|stop tomcat, docker container 등을 start|stop|restart 할건지 prompt로 입력 받아 실행. --- - name: startup or stop docker container hosts: all gather_facts: yes become: yes vars_prompt: - name: container_name # container 이름 입력 받는 변수 prompt: " input container name? " private: no - name: select prompt: " choose start|stop|restart [default: start]? " private: no default: start # default 갓 설정 tasks: - name: "{{ conta..
1.8 ansible | [test][playbook] 파일 내용 수정 [root@ANSIBLE ansible]# cat lineinfile.yml --- - hosts: test02 become: true tasks: - lineinfile: path: /etc/nginx/nginx.conf line: include /etc/nginx/conf.d/*.conf; state: present notify: - restart nginx handlers: - name: restart nginx service: name: nginx state: restarted ## 파일 마지막에 추가됨(있으면 추가 안됨) 그리고 재시작 ## state 파리미터 ## absent : 삭제
1.7 ansible | [test][playbook] nginx 설치 [root@ANSIBLE ansible]# cat install_nginx.yml --- - name: "install nginx" hosts: test1 become: true tasks: - name: "yum install" yum: name: nginx state: installed notify: - restart nginx handlers: - name: restart nginx service: name: nginx state: restarted ## yum 모듈 설치 관련 state 파라미터 ## installed, present : 설치 ## latest : 최신 버전 설치 ## absent, removed : 삭제 ## handlers 는 tasks 와 기본적으로 하는 일은 같으나 차이점은..
1.6 ansible | [test][playbook] multi command [root@OPENLDAP-TEST ansible]# cat multi_command.yml --- - name: "command test" hosts: all become: true tasks: - name: "iptables insert" command: "{{ item }}" with_items: - iptables -D INPUT -s 2.2.2.2 - iptables -D INPUT -s 3.3.3.3 - iptables -D INPUT -s 4.4.4.4 - iptables -D INPUT -s 1.1.1.1 -j ACCEPT ## command, shell 모두 유효 ## with_items 로 여러 명령을 내릴수 있음.
1.5 ansible | [test][playbook] 서비스 데몬 실행 [root@OPENLDAP-TEST ansible]# cat setvice.yml --- - name: "sservice test" hosts: test02 become: true tasks: - name: "service test" service: name: docker state: started ## service관련 state 파라미터 ## started : 서비스 시작 ## stopped : 서비스 종료 ## restarted : 서비스 재시작 ## reloaded : 서비스 리로드
1.4 ansible | [test][playbook] 파일 내용 치환 [root@ANSIBLE ansible]# cat file_replace.yml --- - name: "replace file" hosts: test become: true tasks: - name: "file replcae" replace: path: /etc/hosts regexp: "192.168.6.135 docker2.plo.plo docker2" replace: "192.168.6.135 docker5.plo.plo docker5" ## regexp 내용을 -> replace 내용으로 변경