ceuser@deyu:~/ansible_pb$ ansible-doc copy | grep inline -A3
- name: Copy using inline content
ansible.builtin.copy:
content: '# This file was moved to /etc/other.conf'
dest: /etc/mine.conf
ceuser@deyu:~/ansible_pb$ vi webtest2.yml
ceuser@deyu:~/ansible_pb$ 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
ceuser@deyu:~/ansible_pb$ ansible-playbook webtest2.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 [ansible.builtin.copy] **************************************************** changed: [kvm11] PLAY RECAP ********************************************************************* kvm11 : ok=9 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ceuser@deyu:~/ansible_pb$ ansible dev -m shell -a "cat /webtest/index.html" kvm11 | CHANGED | rc=0 >> WebTest on kvm11
ceuser@deyu:~/ansible_pb$ curl http://kvm11/webtest/index.html ceuser@deyu:~/ansible_pb$ 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。
ceuser@deyu:~/ansible_pb$ ansible dev -m shell -a "ls -Z /webtest" kvm11 | CHANGED | rc=0 >> system_u:object_r:default_t:s0 index.html