Bo's Oracle Station

查看: 1551|回复: 0

ansible11(触发器解决依赖关系)

[复制链接]

75

主题

115

帖子

2718

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2718
发表于 2020-12-12 22:21:40 | 显示全部楼层 |阅读模式

vhosts.conf:
  1. #
  2. #
  3. <VirtualHost *:80>
  4.     DocumentRoot "/var/www/html/serverb"
  5.     ServerName serverb.lab.example.com
  6.     ErrorLog "/var/log/httpd/serverb-error.log"
  7.     CustomLog "/var/log/httpd/serverb-access_log" common
  8. </VirtualHost>

  9. <VirtualHost *:80>
  10.     DocumentRoot "/var/www/html/wwwb"
  11.     ServerName wwwb.lab.example.com
  12.     ErrorLog "/var/log/httpd/wwwb-error.log"
  13.     CustomLog "/var/log/httpd/wwwb-access_log" common
  14. </VirtualHost>

复制代码

  1. ---
  2. - name: Copy httpd Temp Config
  3.   hosts: serverb
  4.   #force_handlers: yes
  5.   tasks:
  6.   - name: Copy httpd  Temp
  7.     copy:
  8.       src: "./v6.d/vhosts.conf"
  9.       dest: "/etc/httpd/conf.d/vhosts.conf"
  10.     notify:
  11.       - h_configfile

  12.   - name: Create Vhosts Dir
  13.     file:
  14.       dest: "/var/www/html/serverb"
  15.       state: directory
  16.     notify:
  17.       - h_direxists_serverb

  18.   - name: Create Vhosts Dir2
  19.     file:
  20.       dest: /var/www/html/wwwb
  21.       state: directory
  22.     notify:
  23.       - h_direxists_wwwb

  24.   - name:
  25.     shell: '/usr/bin/xx'
  26.     ignore_errors: yes

  27.   handlers:
  28.   - name: h_direxists_serverb
  29.     copy:
  30.       content: "Welcome to serverb.lab.example.com."
  31.       dest: "/var/www/html/serverb/index.html"

  32.   - name: h_direxists_wwwb
  33.     copy:
  34.       content: "Welcome to wwwb.example.com."
  35.       dest: "/var/www/html/wwwb/index.html"

  36.   - name: h_configfile
  37.     service:
  38.       name: httpd
  39.       state: restarted

  40. - name: Test Vhosts
  41.   hosts: localhost
  42.   vars:
  43.     v_url:
  44.       - serverb.lab.example.com
  45.       - wwwb.lab.example.com
  46.   tasks:
  47.   - name: Connect
  48.     uri:
  49.       url: "http://{{ item }}"
  50.       return_content: yes
  51.       status_code: 200
  52.     loop:
  53.       "{{ v_url }}"
  54.     register: v_result

  55.   - name: Show
  56.     debug:
  57. #      var: v_result
  58.       msg:
  59.         The result for "{{ item.content }}."
  60.     loop:
  61.       "{{ 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]$



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-27 18:56 , Processed in 0.036728 second(s), 24 queries .

快速回复 返回顶部 返回列表