|
vhosts.conf:
- #
- #
- <VirtualHost *:80>
- DocumentRoot "/var/www/html/serverb"
- ServerName serverb.lab.example.com
- ErrorLog "/var/log/httpd/serverb-error.log"
- CustomLog "/var/log/httpd/serverb-access_log" common
- </VirtualHost>
- <VirtualHost *:80>
- DocumentRoot "/var/www/html/wwwb"
- ServerName wwwb.lab.example.com
- ErrorLog "/var/log/httpd/wwwb-error.log"
- CustomLog "/var/log/httpd/wwwb-access_log" common
- </VirtualHost>
复制代码
- ---
- - name: Copy httpd Temp Config
- hosts: serverb
- #force_handlers: yes
- tasks:
- - name: Copy httpd Temp
- copy:
- src: "./v6.d/vhosts.conf"
- dest: "/etc/httpd/conf.d/vhosts.conf"
- notify:
- - h_configfile
- - name: Create Vhosts Dir
- file:
- dest: "/var/www/html/serverb"
- state: directory
- notify:
- - h_direxists_serverb
- - name: Create Vhosts Dir2
- file:
- dest: /var/www/html/wwwb
- state: directory
- notify:
- - h_direxists_wwwb
- - name:
- shell: '/usr/bin/xx'
- ignore_errors: yes
- handlers:
- - name: h_direxists_serverb
- copy:
- content: "Welcome to serverb.lab.example.com."
- dest: "/var/www/html/serverb/index.html"
- - name: h_direxists_wwwb
- copy:
- content: "Welcome to wwwb.example.com."
- dest: "/var/www/html/wwwb/index.html"
- - name: h_configfile
- service:
- name: httpd
- state: restarted
- - name: Test Vhosts
- hosts: localhost
- vars:
- v_url:
- - serverb.lab.example.com
- - wwwb.lab.example.com
- tasks:
- - name: Connect
- uri:
- url: "http://{{ item }}"
- return_content: yes
- status_code: 200
- loop:
- "{{ v_url }}"
- register: v_result
- - name: Show
- debug:
- # var: v_result
- msg:
- The result for "{{ item.content }}."
- loop:
- "{{ v_result.results }}"
复制代码
[student@workstation ansible]$ ansible-playbook v6-1_server2.yml
PLAY [Copy httpd Temp Config] *****************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************************
ok: [serverb]
TASK [Copy httpd Temp] ***********************************************************************************************************************************
changed: [serverb]
TASK [Create Vhosts Dir] **********************************************************************************************************************************
ok: [serverb]
TASK [Create Vhosts Dir2] *********************************************************************************************************************************
ok: [serverb]
TASK [shell] **********************************************************************************************************************************************
fatal: [serverb]: FAILED! => {"changed": true, "cmd": "/usr/bin/xx", "delta": "0:00:00.004409", "end": "2020-12-12 22:16:44.974898", "msg": "non-zero return code", "rc": 127, "start": "2020-12-12 22:16:44.970489", "stderr": "/bin/sh: /usr/bin/xx: No such file or directory", "stderr_lines": ["/bin/sh: /usr/bin/xx: No such file or directory"], "stdout": "", "stdout_lines": []}
...ignoring
RUNNING HANDLER [h_configfile] ****************************************************************************************************************************
changed: [serverb]
PLAY [Test Vhosts] ****************************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************************
ok: [localhost]
TASK [Connect] ********************************************************************************************************************************************
ok: [localhost] => (item=serverb.lab.example.com)
ok: [localhost] => (item=wwwb.lab.example.com)
TASK [Show] ***********************************************************************************************************************************************
ok: [localhost] => (item={'content': 'Welcome to serverb.lab.example.com.', 'redirected': False, 'url': 'http://serverb.lab.example.com', 'date': 'Sat, 12 Dec 2020 14:16:50 GMT', 'server': 'Apache/2.4.37 (Red Hat Enterprise Linux)', 'last_modified': 'Sat, 12 Dec 2020 14:14:46 GMT', 'etag': '"23-5b64507fe9126"', 'accept_ranges': 'bytes', 'content_length': '35', 'connection': 'close', 'content_type': 'text/html; charset=UTF-8', 'cookies_string': '', 'cookies': {}, 'msg': 'OK (35 bytes)', 'status': 200, 'elapsed': 0, 'changed': False, 'invocation': {'module_args': {'url': 'http://serverb.lab.example.com', 'return_content': True, 'status_code': ['200'], 'force': False, 'http_agent': 'ansible-httpget', 'use_proxy': True, 'validate_certs': True, 'force_basic_auth': False, 'body_format': 'raw', 'method': 'GET', 'follow_redirects': 'safe', 'timeout': 30, 'headers': {}, 'follow': False, 'url_username': None, 'url_password': None, 'client_cert': None, 'client_key': None, 'dest': None, 'body': None, 'src': None, 'creates': None, 'removes': None, 'unix_socket': None, 'mode': None, 'owner': None, 'group': None, 'seuser': None, 'serole': None, 'selevel': None, 'setype': None, 'attributes': None, 'content': None, 'backup': None, 'remote_src': None, 'regexp': None, 'delimiter': None, 'directory_mode': None, 'unsafe_writes': None}}, 'failed': False, 'item': 'serverb.lab.example.com', 'ansible_loop_var': 'item'}) => {
"msg": "The result for \"Welcome to serverb.lab.example.com..\""
}
ok: [localhost] => (item={'content': 'Welcome to wwwb.example.com.', 'redirected': False, 'url': 'http://wwwb.lab.example.com', 'date': 'Sat, 12 Dec 2020 14:16:51 GMT', 'server': 'Apache/2.4.37 (Red Hat Enterprise Linux)', 'last_modified': 'Sat, 12 Dec 2020 14:14:48 GMT', 'etag': '"1c-5b645081685f6"', 'accept_ranges': 'bytes', 'content_length': '28', 'connection': 'close', 'content_type': 'text/html; charset=UTF-8', 'cookies_string': '', 'cookies': {}, 'msg': 'OK (28 bytes)', 'status': 200, 'elapsed': 0, 'changed': False, 'invocation': {'module_args': {'url': 'http://wwwb.lab.example.com', 'return_content': True, 'status_code': ['200'], 'force': False, 'http_agent': 'ansible-httpget', 'use_proxy': True, 'validate_certs': True, 'force_basic_auth': False, 'body_format': 'raw', 'method': 'GET', 'follow_redirects': 'safe', 'timeout': 30, 'headers': {}, 'follow': False, 'url_username': None, 'url_password': None, 'client_cert': None, 'client_key': None, 'dest': None, 'body': None, 'src': None, 'creates': None, 'removes': None, 'unix_socket': None, 'mode': None, 'owner': None, 'group': None, 'seuser': None, 'serole': None, 'selevel': None, 'setype': None, 'attributes': None, 'content': None, 'backup': None, 'remote_src': None, 'regexp': None, 'delimiter': None, 'directory_mode': None, 'unsafe_writes': None}}, 'failed': False, 'item': 'wwwb.lab.example.com', 'ansible_loop_var': 'item'}) => {
"msg": "The result for \"Welcome to wwwb.example.com..\""
}
PLAY RECAP ************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
serverb : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
[student@workstation ansible]$
|
|