Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
joohanhong
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JooHan Hong
joohanhong
Commits
1dac4687
Commit
1dac4687
authored
Mar 10, 2021
by
JooHan Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file_copy init
parent
1f90954e
Pipeline
#5134
passed with stages
in 4 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
README.md
ANSIBLE/OS/FILE_COPY/README.md
+83
-0
No files found.
ANSIBLE/OS/FILE_COPY/README.md
0 → 100644
View file @
1dac4687
[
![logo
](
https://www.hongsnet.net/images/logo.gif
)
](https://www.hongsnet.net)
# Ansible의 copy 모듈을 이용한 파일 가져오기
> 원격 시스템에 디렉토리 및 파일을 복사한다.
## 활용 용도
-
FTP를 사용하지않고, 원격서버에 디렉토리 및 파일을 복사할 수 있다.
-
보안취약점 스크립트를 원격서버에 업로드하는 용도로 사용
## Inventory 설정
```
bash
# cat hosts
[
ALL_HOSTS]
172.16.0.100
managed_ip
=
172.16.0.100
des
=
"2020-12-03"
[
ALL_HOSTS_OK]
```
대상 호스트는 172.16.0.100이며, 추가는 2020-12-03에 수행한다. 참고적으로
**ALL_HOSTS_OK**
호스트 그룹은 작업이 완료된 호스트의 history를 위한 그룹이다.
## Host Variables 설정
```
bash
# cat host_vars/172.16.0.100
ansible_ssh_host: 172.16.0.100
ansible_ssh_port: SSH_포트번호
ansible_ssh_user: 사용자 아이디
ansible_ssh_pass:
"사용자 패스워드"
ansible_become:
yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass:
"!root_패스워드"
ansible_python_interpreter: python2.7
```
## Playbook 설정
```python
---
-
name: OS Secure Running
hosts: ALL_HOSTS
tasks:
-
name: Directory Create
file:
path: "{{ item }}"
state: directory
owner: 'root'
group: 'root'
mode: 0700
with_items:
-
/root/test
- name: Secure Script File Copy
copy:
src: "{{ item }}"
dest: /root/test
owner: 'root'
group: 'root'
mode: 0700
#attr: i
with_items:
- secure.sh
- test.sh
```
`File copy`에 대한 Playbook 분석
* [ ] 다수의 파일을 사용하려면, copy 모듈이 아닌 synchronize(rsync) 모듈을 사용하도록 권장하고 있다.
- https://docs.ansible.com/ansible/2.5/modules/copy_module.html
* [ ] with_items 모듈을 사용하여, 하나 이상의 파일들을 원격서버에 복사한다.
## playbook 실행
```
bash
# ansible-playbook -i hosts file_copy.yml
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment