Bo's Oracle Station

查看: 1264|回复: 0

ansible2

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-12-9 20:49:15 | 显示全部楼层 |阅读模式
v2-1_webgroup.yml:
  1. ---
  2. - name: Play to Setup Webservers
  3.   hosts: webgroup
  4.   tasks:
  5.   - name: Yum Install:httpd
  6.     yum:
  7.       name: httpd
  8.       state: latest

  9.   - name: Running:httpd Service
  10.     service:
  11.       name: httpd
  12.       state: started
  13.       enabled: yes

  14.   - name: Create Homepages
  15.     lineinfile:
  16.       path: /var/www/html/index.html
  17.       line: "welcome to {{ inventory_hostname }}\n<a href="http://{{ inventory_hostname }}/again.html">AGAIN LINK</a>"
  18.       create: yes

  19.   - name: Create Content
  20.     copy:
  21.       content: "Welcome to {{ inventory_hostname }} again"
  22.       dest: /var/www/html/again.html

  23.   - name: Firewall
  24.     firewalld:
  25.       service: http
  26.       permanent: yes
  27.       state: enabled
  28.       immediate: yes

  29. - name: Test Homepage
  30.   hosts: localhost
  31.   connection: local
  32.   vars:
  33.     v_url:
  34.      - http://serverc.lab.example.com
  35.      - http://serverd.lab.example.com
  36.   tags:
  37.   - tag1

  38.   tasks:
  39.   - name: Connect to the webservers
  40.     uri:
  41.       url: "{{ item }}"
  42.       # validate_certs: no
  43.       # force_basic_auth: no
  44.       # user: testuser1
  45.       # password: redhat123
  46.       return_content: yes
  47.       status_code: 200
  48.     register: v_return
  49.     loop:
  50.       "{{ v_url }}"

  51.   - name: debug   
  52.     debug:
  53.       var: v_return

  54.       # msg:
  55.       #  "{{ v_return}}"
复制代码
v2-2_webgroup.yml:
  1. ---
  2. - name: Play to Setup Webserver
  3.   hosts: webgroup
  4.   gather_facts: no
  5.   tasks:
  6.   - name: yum install httpd
  7.     yum:
  8.       name: httpd
  9.       state: latest

  10.   - name: Running:httpd Service
  11.     service:
  12.       name: httpd
  13.       state: started
  14.       enabled: yes

  15.   - name: Create Content
  16.     copy:
  17.       content: "HELLO WORLD {{ inventory_hostname }}"
  18.       dest: /var/www/html/index.html
  19.       follow: yes

  20.   - name: Create Homepage
  21.     lineinfile:
  22.       path: /var/www/html/index.html
  23.       line: "welcome to shendata on {{ inventory_hostname }}"
  24.       create: yes

  25.   - name: firewall
  26.     firewalld:
  27.       service: http
  28.       permanent: yes
  29.       state: enabled
  30.       immediate: yes

  31. - name: Test Homepage
  32.   hosts: localhost
  33.   gather_facts: no
  34.   tags:
  35.   - tag1

  36.   tasks:
  37.   - name: Connect to the serverc
  38.     uri:
  39.       url: http://serverc.lab.example.com
  40.       return_content: yes
  41.       status_code: 200
  42.     register: v_result_1

  43.   - name: Connect to the serverd
  44.     uri:
  45.       url: http://serverd.lab.example.com
  46.       return_content: yes
  47.       status_code: 200
  48.     register: v_result_2

  49.   - name: debug   
  50.     debug:
  51.       var: "{{ item }}"
  52.     loop:
  53.       - v_result_1.status
  54.       - v_result_1.content
  55.       - v_result_2.status
  56.       - v_result_2.content
复制代码




回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-29 07:02 , Processed in 0.039491 second(s), 24 queries .

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