반응형
- 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: "{{ container_name }} docker container {{ select }} tasks starting.."
shell: docker "{{ select }}" "{{ container_name }}"
register: execute_result
- debug:
msg:
- "{{ container_name }}"
- "{{ select }}"
- "{{ execute_result.stdout }}"
## 결과
[root@ANSIBLE ansible]# ansible-playbook prompt.yml
input container name? : awx_web
choose start|stop|restart [default: start]? [start]: stop
PLAY [startup or stop docker container] ******************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************
ok: [test02]
TASK [awx_web docker container stop tasks starting..] ****************************************************************************************************************************
changed: [test02]
TASK [debug] *********************************************************************************************************************************************************************
ok: [test02] => {
"msg": [
"awx_web",
"stop",
"awx_web"
]
}
PLAY RECAP ***********************************************************************************************************************************************************************
test02 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@ANSIBLE ansible]# ansible-playbook prompt.yml
input container name? : awx_web
choose start|stop|restart [default: start]? [start]:
PLAY [startup or stop docker container] ******************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************
ok: [test02]
TASK [awx_web docker container start tasks starting..] ***************************************************************************************************************************
changed: [test02]
TASK [debug] *********************************************************************************************************************************************************************
ok: [test02] => {
"msg": [
"awx_web",
"start",
"awx_web"
]
}
PLAY RECAP ***********************************************************************************************************************************************************************
test02 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- tomcat
---
- name: startup or stop servers
hosts: all
gather_facts: yes vars_prompt:
- name: select
prompt: "startup or stop servers? [default: startup] "
private: no
default: 'startup'
tasks:
- name: "{{ select }} tasks starting"
shell: nohup "./{{ select }}.sh"
args:
chdir: /data/wasadm/apache-tomcat-8.5.50/bin ## tomcat 위치 이동
become_user: yelloweb ## su user 설정
register: execute_result
- debug:
msg:
- "{{ execute_result.stdout }}"
반응형
'Automation Tools > Ansible' 카테고리의 다른 글
2.2 ansible | [roles][CentOS 시스템 초기 설정] vars (0) | 2021.03.16 |
---|---|
2.1 ansible | [roles][CentOS 시스템 초기 설정] README (0) | 2021.03.16 |
1.8 ansible | [test][playbook] 파일 내용 수정 (0) | 2021.03.16 |
1.7 ansible | [test][playbook] nginx 설치 (0) | 2021.03.16 |
1.6 ansible | [test][playbook] multi command (0) | 2021.03.16 |