playbook 을 사용하여 파일 복사
playbook 파일 내용 (filecopy.yml)
- 복제 대상 정보는 inventory 파일에 기록
$ cat inventory
[Server]
10.10.10.101
$ cat filecopy.yml
- name: file copy
hosts: Server
vars:
ansible_ssh_user: ansible
tasks:
- name: file copy
ansible.builtin.copy:
src: /home/ansible/test.txt
dest: /home/ansible/test.txt
owner: ansible
group: ansible
파일 복제
$ ansible-playbook -i inventory filecopy.yml
$ ansible-playbook -i inventory filecopy.yml
SSH password:
BECOME password[defaults to SSH password]:
PLAY [file copy] *************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************
ok: [10.10.10.101]
TASK [file copy] *************************************************************************************************************************
changed: [10.10.10.101]
PLAY RECAP *******************************************************************************************************************************
10.10.10.101 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
복제 파일 변경 없이 동일한 playbook 재적용 시
$ ansible-playbook -i inventory filecopy.yml
SSH password:
BECOME password[defaults to SSH password]:
PLAY [file copy] *************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************
ok: [10.10.10.101]
TASK [file copy] *************************************************************************************************************************
ok: [10.10.10.101]
PLAY RECAP *******************************************************************************************************************************
10.10.10.101 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0