Bo's Oracle Station

查看: 938|回复: 0

ANSIBLE4

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-8-8 15:12:42 | 显示全部楼层 |阅读模式
  1. ---
  2. - name: Play to Setup Webserver
  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 Content
  15.     copy:
  16.       content: "HELLO WORLD {{ inventory_hostname }}"
  17.       dest: /var/www/html/index.html
  18.       follow: yes

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

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

  30. - name: Test Homepage
  31.   hosts: localhost
  32.   tags:
  33.   - tag1

  34.   tasks:
  35.   - name: Connect to the server1
  36.     uri:
  37.       url: http://server1.example.com
  38.       return_content: yes
  39.       status_code: 200
  40.     register: v_result_1

  41.   - name: Connect to the server2
  42.     uri:
  43.       url: http://server2.example.com
  44.       return_content: yes
  45.       status_code: 200
  46.     register: v_result_2

  47.   - name: debug   
  48.     debug:
  49.       var: "{{ item }}"
  50.     with_items:
  51.       - v_result_1.status
  52.       - v_result_1.content
  53.       - v_result_2.status
  54.       - v_result_2.content
复制代码
  1. ---
  2. - name: Create User Accounts for All Machines
  3.   hosts: srvgroup
  4.   vars_files:
  5.     - ./v3.d/secret.yml
  6.   tasks:
  7.   - name: Createing User from secret.yml
  8.     user:
  9.       name: "{{ username }}"
  10.       password: "{{ password }}"
复制代码
username: spoto
password: $6$...............


  1. [student@classroom v3.d]$ ansible-vault    encrypt  secret.yml
复制代码




./v3.d/secret.yml:
  1. $ANSIBLE_VAULT;1.1;AES256
  2. 39613736373965373634393264613163343832383537316564396535626539633039373037326264
  3. 6530323366663730336236636239303837646161656635340a303265636166383636333935373962
  4. 31633838653263666164363062613832353765323231303530313931383237303966306361386538
  5. 6363336466363562370a626632613965383636396638306131356561663536373431396330303539
  6. 35373633323334663862613537633239626265643534633735313533333432633462393536666636
  7. 62356531363637626630363933613961356333666635663731366632303239386366663263343664
  8. 38393837323762656534656661346265313262393530333130396538333936386233373434623637
  9. 39313438646232643933383537343762366363666134663639356133643732383232373739376163
  10. 34363365653965653234326131323336633036333538656638633664396435616634303530326337
  11. 37363639653536666237623466663762313265646565653366346361303065373066313636623565
  12. 623864353336663330313134653638303134
复制代码

  1. [student@classroom ansible]$ ansible-playbook  v3-1_srvgroup_E.yml --ask-vault-pass
复制代码
  1. [student@classroom ansible]$ ansible-playbook v3-1_srvgroup_E.yml  --vault-password-file=./v3.d/vault.pass
复制代码




回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-9 19:03 , Processed in 0.034751 second(s), 24 queries .

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