[deyu1@kvm19 ansible]$ ansible-doc copy
- name: Copy using inline content
ansible.builtin.copy:
content: '# This file was moved to /etc/other.conf'
dest: /etc/mine.conf
[deyu1@kvm19 ansible]$ vim webtest2.yml
[deyu1@kvm19 ansible]$ cat webtest2.yml
---
- name: Web test
hosts: dev
roles:
- apache
tasks:
- ansible.builtin.file:
path: /webtest
state: directory
group: webtest
mode: '2775'
- ansible.builtin.file:
src: /webtest
dest: /var/www/html/webtest
state: link
- ansible.builtin.copy:
content: "WebTest on {{ ansible_hostname }}\n"
dest: /webtest/index.html
[deyu1@kvm19 ansible]$ ansible-playbook webtest.yml PLAY [Web test] ***************************************************************** TASK [Gathering Facts] ********************************************************** ok: [kvm11] TASK [apache : install the latest version of Apache] **************************** ok: [kvm11] TASK [apache : Start service httpd] ********************************************* ok: [kvm11] TASK [apache : Enable service firewalld] **************************************** ok: [kvm11] TASK [apache : firewalld add http service] ************************************** ok: [kvm11] TASK [apache : Template a file] ************************************************* ok: [kvm11] TASK [ansible.builtin.file] ***************************************************** ok: [kvm11] TASK [ansible.builtin.file] ***************************************************** ok: [kvm11] TASK [copy] ********************************************************************* ok: [kvm11] PLAY RECAP ********************************************************************** kvm11 : ok=9 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[deyu1@kvm19 ansible]$ ansible dev -m shell -a "cat /webtest/index.html" kvm11 | CHANGED | rc=0 >> WebTest on kvm11
[deyu1@kvm19 ansible]$ curl http://kvm11/webtest/index.html [deyu1@kvm19 ansible]$ curl http://kvm11/webtest/ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access this resource.</p> </body></html>
default_t,不是網頁的 httpd_sys_content_t。
[deyu1@kvm19 ansible]$ ansible dev -m shell -a "ls -Z /webtest" kvm11 | CHANGED | rc=0 >> system_u:object_r:default_t:s0 index.html