posted by 귀염둥이채원 2019. 1. 29. 18:19

Ansible은 기본적으로 play를 병렬로 실행한다.

Rolling Update를 수행하려면 serial 키워드를 사용하면 된다.


serial 키워드는 한 번에 얼마나 많은 서버에 명령을 수행할지 알려줍니다.

serial 키워드를 지정하지 않으면 구성 파일에 지정된 기본 fork 한도까지 병렬 처리합니다.


serial keyword를 이용한 rolling update

 - name: test play

  hosts: webservers

  serial: 1

  gather_facts: False

  tasks:

  - name: task one

    comand: hostname

  - name: task two

    command: hostname


# 참고 사이트

https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html

https://stackoverflow.com/questions/27315469/ansible-how-to-sequentially-execute-playbook-for-each-host



'Tool > ansible' 카테고리의 다른 글

ansible role template 생성하기  (0) 2019.02.01
ansible handler란?  (0) 2019.02.01
ansible-vault를 이용한 암호화  (0) 2019.01.29
ansible source build  (0) 2019.01.29
fail module 사용법 정리  (0) 2019.01.29
posted by 귀염둥이채원 2019. 1. 29. 18:18

Ansible Vault는 패스워드, 키와 같은 보안에 민감한 파일들을 암복호화해주는 기능이다.
Ansbile에서 사용하는 모든 구조화된 데이터 파일을 암호화 할수 있다.
참고로 ansible을 설치하면 ansible-vault도 설치가 된다.

# ansible-vault 

 Usage: ansible-vault [create|decrypt|edit|encrypt|encrypt_string|rekey|view] [options] [vaultfile.yml]

encryption/decryption utility for Ansible data files

Options:
--ask-vault-pass ask for vault password
-h, --help show this help message and exit
--new-vault-id=NEW_VAULT_ID
the new vault identity to use for rekey
--new-vault-password-file=NEW_VAULT_PASSWORD_FILES
new vault password file for rekey
--vault-id=VAULT_IDS the vault identity to use
--vault-password-file=VAULT_PASSWORD_FILES
vault password file
-v, --verbose verbose mode (-vvv for more, -vvvv to enable
connection debugging)
--version show program's version number and exit

See 'ansible-vault <command> --help' for more information on a specific




# 암호화된 파일을 생성하기
$ ansible-vault create foo.yml

# 암호화된 파일 수정하기
$ ansible-vault edit foo.yml

# 암호화된 파일의 패스워드 변경하기
$ ansible-vault rekey foo.yml

# 암호화되지 않은 파일을 암호화
$ ansible-vault encrypt foo.yml

# 암호화된 파일의 복호화
$ ansible-vault decrypt foo.yml

# 암호화된 파일의 내용 보기
$ ansible-vault view foo.yml


# ansible-vault를 사용해보기
1. hosts 파일을 암호화
[test@1ff25a8ed818 dse]$ ls
common_vars files group_vars hosts play.yml README.md roles


[test@1ff25a8ed818 dse]$ ansible-vault encrypt hosts

New Vault password: test
Confirm New Vault password: test
Encryption successful


2. 암호화된 hosts 파일 내용 확인
[test@1ff25a8ed818 dse]$ ansible-vault encrypt hosts
New Vault password: test
Confirm New Vault password: test
Encryption successful
[test@1ff25a8ed818 dse]$ ansible-vault view hosts


3. playbook 실행하기
ansible-playbook 실행시 --ask-vault-pass 옵션을 넣어주면 된다.
[test@1ff25a8ed818 dse]$ ansible-playbook --ask-vault-pass -i hosts play.yml -t install
Vault password:

파일에 vault password를 저장해서 사용이 가능하다.
[test@1ff25a8ed818 dse]$ cat vault_pass.txt
test
[test@1ff25a8ed818 dse]$ ansible-playbook -i hosts play.yml -t install --vault-password-file=vault_pass.txt


# 참고 사이트
https://docs.ansible.com/ansible/2.5/user_guide/vault.html

'Tool > ansible' 카테고리의 다른 글

ansible role template 생성하기  (0) 2019.02.01
ansible handler란?  (0) 2019.02.01
serial keyword를 이용한 rolling update  (0) 2019.01.29
ansible source build  (0) 2019.01.29
fail module 사용법 정리  (0) 2019.01.29
posted by 귀염둥이채원 2019. 1. 29. 18:15

CentOS에서 ansible source build 방법을 정리한다.


$ yum install epel-release
$ yum install python-pip
$ pip install paramiko PyYAML jinja2 httplib2
$ git clone https://github.com/ansible/ansible.git --recursive
$ cd ./ansible
$ git checkout tags/v2.4.2.0-1
$ source ./hacking/env-setup


# 참고 사이트
https://docs.ansible.com/ansible/2.7/installation_guide/intro_installation.html
https://www.lesstif.com/pages/viewpage.action?pageId=22052879

'Tool > ansible' 카테고리의 다른 글

ansible role template 생성하기  (0) 2019.02.01
ansible handler란?  (0) 2019.02.01
serial keyword를 이용한 rolling update  (0) 2019.01.29
ansible-vault를 이용한 암호화  (0) 2019.01.29
fail module 사용법 정리  (0) 2019.01.29
posted by 귀염둥이채원 2019. 1. 29. 18:14

when 조건에 만족하는 경우,

message에 정의된 내용을 출력해준다.


# example

# Example playbook using fail and when together

- fail:

    msg: "The system may not be provisioned according to the CMDB status."

  when: cmdb_status != "to-be-staged" 


- name: fail the play if the previous command did not succeed

  fail:

    msg: "the command failed"

  when: "'FAILED' in command_result.stderr" 


# 참고 사이트

https://docs.ansible.com/ansible/latest/modules/fail_module.html

https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html

https://ansible-manual.readthedocs.io/en/v1.8.4-doc/playbooks_error_handling.html

'Tool > ansible' 카테고리의 다른 글

ansible role template 생성하기  (0) 2019.02.01
ansible handler란?  (0) 2019.02.01
serial keyword를 이용한 rolling update  (0) 2019.01.29
ansible-vault를 이용한 암호화  (0) 2019.01.29
ansible source build  (0) 2019.01.29
posted by 귀염둥이채원 2019. 1. 29. 17:53

vi에서 파일을 열고 내용을 붙여넣기 하다보면 indent가 깨지는 현상이 발생하는 경우가 있다.

이러한 경우에 붙여넣기 전에 vi에서 아래 명령을 실행한다.

:set paste


원래대로 복구하려면 

:set nopaste


# 참고 사이트

https://www.lesstif.com/pages/viewpage.action?pageId=6979764

https://happyoutlet.tistory.com/entry/vim-vim%EC%9C%BC%EB%A1%9C-%EB%B6%99%EC%97%AC%EB%84%A3%EA%B8%B0-%ED%96%88%EC%9D%84-%EB%95%8C-%EA%B3%84%EB%8B%A8%ED%98%84%EC%83%81-%EC%97%86%EC%95%A0%EA%B8%B0

'Tool > vim' 카테고리의 다른 글

탭 설정 및 들여쓰기 방법  (0) 2019.01.31
vi, vim ^M 제거하는 방법  (0) 2019.01.29
posted by 귀염둥이채원 2019. 1. 29. 17:03

윈도우에서 작성한 파일을 리눅스에 옮기게 되면 개행문자가 깨져서 ^M 표시가 된다.

윈도우에서는 CRLF가 개행이지만, 리눅스에서는 LF가 개행이 아니라서 발생하는 현상이다.


[CR,LF란?]

라인피드(LF : Line Feed) => 현재 위치에서 바로 아래로 이동

캐리지리턴(CR: Carriage return) => 커서의 위치를 앞으로 이동


# vi, vim에서 ^M 제거하는 방법

:%s/^M//g



'Tool > vim' 카테고리의 다른 글

탭 설정 및 들여쓰기 방법  (0) 2019.01.31
vi, vim에서 붙여넣기 할때 indent 깨지는 현상 해결  (0) 2019.01.29
posted by 귀염둥이채원 2019. 1. 24. 15:07

feature branch에서 수정후 아래와 같이 commit --amend를 수행했더니 에러가 발생했다.

$ git commit --amend


# 에러

fatal: You are in the middle of a merge -- cannot amend.

당신은 병합 중간에 있습니다 - 수정할 수 없습니다.


# 해결

.git/MERGE_HEAD 파일을 삭제한다.


# 참고사이트

https://stackoverflow.com/questions/22135465/cant-commit-after-starting-a-merge-in-sourcetree

'Tool > git' 카테고리의 다른 글

파일 및 디렉토리 삭제: git rm --cached  (0) 2019.03.11
Git commit --amend로 마지막 커밋 수정하기  (0) 2019.02.08
git submodule이란?  (0) 2019.02.08