botang 发表于 2020-12-9 20:49:15

ansible2

v2-1_webgroup.yml:
---
- name: Play to Setup Webservers
hosts: webgroup
tasks:
- name: Yum Install:httpd
    yum:
      name: httpd
      state: latest

- name: Running:httpd Service
    service:
      name: httpd
      state: started
      enabled: yes

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

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

- name: Firewall
    firewalld:
      service: http
      permanent: yes
      state: enabled
      immediate: yes

- name: Test Homepage
hosts: localhost
connection: local
vars:
    v_url:
   - http://serverc.lab.example.com
   - http://serverd.lab.example.com
tags:
- tag1

tasks:
- name: Connect to the webservers
    uri:
      url: "{{ item }}"
      # validate_certs: no
      # force_basic_auth: no
      # user: testuser1
      # password: redhat123
      return_content: yes
      status_code: 200
    register: v_return
    loop:
      "{{ v_url }}"

- name: debug   
    debug:
      var: v_return

      # msg:
      #"{{ v_return}}"
v2-2_webgroup.yml:
---
- name: Play to Setup Webserver
hosts: webgroup
gather_facts: no
tasks:
- name: yum install httpd
    yum:
      name: httpd
      state: latest

- name: Running:httpd Service
    service:
      name: httpd
      state: started
      enabled: yes

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

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

- name: firewall
    firewalld:
      service: http
      permanent: yes
      state: enabled
      immediate: yes

- name: Test Homepage
hosts: localhost
gather_facts: no
tags:
- tag1

tasks:
- name: Connect to the serverc
    uri:
      url: http://serverc.lab.example.com
      return_content: yes
      status_code: 200
    register: v_result_1

- name: Connect to the serverd
    uri:
      url: http://serverd.lab.example.com
      return_content: yes
      status_code: 200
    register: v_result_2

- name: debug   
    debug:
      var: "{{ item }}"
    loop:
      - v_result_1.status
      - v_result_1.content
      - v_result_2.status
      - v_result_2.content




页: [1]
查看完整版本: ansible2