Ansible Module 활용 - Shell > Ansible 자료실

본문 바로가기
사이트 내 전체검색

Ansible 자료실

실습 Ansible Module 활용 - Shell

페이지 정보

profile_image
작성자 AnsibleM
댓글 0건 조회 10,534회 작성일 21-10-07 13:01

본문

1. 정의

shell 모듈은 관리 노드의 shell(/bin/sh) 명령을 실행합니다.
하지만 유사한 기능을 하는 모듈인 command 모듈을 사용하여 진행하는 것이 더 안정적입니다.
자세한 내용은 아래의 링크를 참고하면 됩니다.
https://docs.ansible.com/ansible/2.9/modules/shell_module.html#notes

2. 모듈 활용 예시

1
2
- name: 원격 노드의 somescript.sh 결과를 somelog.txt에 추가합니다.
  shell: somescript.sh >> somelog.txt
cs


1
2
3
4
- name: 원격 노드의 somedir/ 디렉토리에서 작업하며 somescript.sh 결과를 somelog.txt에 추가합니다.
  shell: somescript.sh >> somelog.txt
  args:
    chdir: somedir/
cs


1
2
3
4
5
- name: 원격 노드의 somedir/ 디렉토리에서 작업하며 somedir/somelog.txt 가 존재하지 않을 경우, somescript.sh 결과를 somelog.txt에 추가합니다.
  shell: somescript.sh >> somelog.txt
  args:
    chdir: somedir/
    creates: somelog.txt
cs


1
2
3
4
- name: curl을 사용하여 SOCKS 프록시를 통해 호스트에 연결합니다 (ansible에서 지원하진 않음). 경고 구문도 표시되진 않습니다.
  shell: curl --socks5 localhost:9000 http://www.ansible.com
  args:
    warn: no
cs


1
2
3
4
- name: Mysql 로그인(mysql 정보 변수가 저장되어 있는 경우)
  shell: mysql -h {{ db_host }} -u {{ db_user }} -p
  args:
    stdin: "{{ db_password }}"
cs


3. 모듈 옵션

chdir(path) : 작업 디렉토리 경로 / 명령 실행 전 디렉터리 이동
cmd(string) : args 안에 옵션들을 실행한 후
creates(path) : 생성 파일 경로 / 파일이 존재할 경우 건너 뜀.
executable(path) : 명령을 실행하는 데 사용되는 shell 변경 ex) /bin/bash
free_form(string) : 옵션이 아님 / 실행할 shell 형식이 자유롭다는 것을 의미
removes(path) : 삭제 파일 경로 / 파일이 존재하지 않을 경우 건너 뜀
stdin(string) : shell 명령 후 입력해야 하는 값을 직접 설정
stdin_add_newline(boolean) :stdin 데이터에 줄바꿈 사용 여부 ex) stdin_add_newline: yes
warn(boolean) : 작업에 대한 경고 표시 활성화 유무 ex) warn: yes

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : (주)리눅스데이타시스템 / 대표 : 정정모
서울본사 : 서울특별시 강남구 봉은사로 114길 40 홍선빌딩 2층 / tel : 02-6207-1160
대전지사 : 대전광역시 유성구 노은로174 도원프라자 5층 / tel : 042-331-1161

접속자집계

오늘
1,220
어제
1,434
최대
3,935
전체
802,369
Copyright © www.linuxdata.org All rights reserved.