[email protected] ~ / cat 1.txt Mission / Case study / cat a1.yml hosts: eisc / representative eisc The grouped host is executed ,all It's al...">

当前位置:网站首页>Example description and case of ansible playbook automated cluster server management

Example description and case of ansible playbook automated cluster server management

2022-06-24 16:52:00 eisc

[[email protected] ~]# cat 1.txt 
  Mission 
#  Case study 
# cat a1.yml
---
- hosts: eisc                 #  representative eisc The grouped host is executed ,all  It's all the hosts 
  remote_user: root     # With root execute 
  tasks:
    - name:  Check the disk 
      shell: df -h; echo " --------------------------------------------------------------"; free -m; echo " start-up  ansible  write file " >> ansible.txt; date
      register: disk
                                    #  perform  shell  The statement command cannot start with echo  sentence , Otherwise, the following statements will not be executed if they are printed directly 
    - name:  process 
      command: ps -u root
      register: ps
    - debug: msg="{{disk.stdout,ps.stdout}}"
                                    #  Read the results after execution 
    - local_action: copy content={{disk.stdout,ps.stdout}} dest=/root/aplaybook.txt
                                    #  Write the result information to the file 
#  explain 
cat playbook.yml
---                                           # Fixed format 
- hosts: 192.168.1.31              # Define the host or host group that needs to be executed 
  remote_user: root                # Remote users 
  vars:                                     # Defining variables 
    http_port: 8088                 # Variable 
  tasks:                                   # Define a task 
    - name: create new file          # Define the name of the task 
      file: name=/tmp/playtest.txt state=touch   # Call module , Specific things to do 
    - name: install package
      yum: name=httpd
    - name: config httpd
      template: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf
      notify:                              # trigger , What to do when the condition is triggered , coordination handlers Use 
        - restart apache            # Need to reference handlers Name 
    - name: copy index.html
      copy: src=/var/www/html/index.html dest=/var/www/html/index.html
    - name: start httpd
      service: name=httpd state=started
  handlers:                            #notify The defined trigger executes the corresponding processing action 
    - name: restart apache                     
                                             # To work with notify The definition is the same 
      service: name=httpd state=restarted      
                                            # Trigger the action to be performed 
#  Related links 
centos  install  ansible  Cluster management application :https://www.eisc.cn/index.php?c=read&id=484&page=1
原网站

版权声明
本文为[eisc]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/04/20210406143128790f.html