botang 发表于 2020-8-8 15:12:42

ANSIBLE4

---
- name: Play to Setup Webserver
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 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
tags:
- tag1

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

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

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

---
- name: Create User Accounts for All Machines
hosts: srvgroup
vars_files:
    - ./v3.d/secret.yml
tasks:
- name: Createing User from secret.yml
    user:
      name: "{{ username }}"
      password: "{{ password }}"
username: spoto
password: $6$...............


$ ansible-vault    encryptsecret.yml



./v3.d/secret.yml:
$ANSIBLE_VAULT;1.1;AES256
39613736373965373634393264613163343832383537316564396535626539633039373037326264
6530323366663730336236636239303837646161656635340a303265636166383636333935373962
31633838653263666164363062613832353765323231303530313931383237303966306361386538
6363336466363562370a626632613965383636396638306131356561663536373431396330303539
35373633323334663862613537633239626265643534633735313533333432633462393536666636
62356531363637626630363933613961356333666635663731366632303239386366663263343664
38393837323762656534656661346265313262393530333130396538333936386233373434623637
39313438646232643933383537343762366363666134663639356133643732383232373739376163
34363365653965653234326131323336633036333538656638633664396435616634303530326337
37363639653536666237623466663762313265646565653366346361303065373066313636623565
623864353336663330313134653638303134

$ ansible-playbookv3-1_srvgroup_E.yml --ask-vault-pass

$ ansible-playbook v3-1_srvgroup_E.yml--vault-password-file=./v3.d/vault.pass



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