• 8.ansible 判断功能


    如何指定判断条件:
    (ansible_hostname == "nfs01")
    (ansible_hostname == "web01")
    setup模块中显示被管理主机系统的详细信息

    - hosts: oldboy
      remote_user: root
      tasks:
        - name: Check File
          file: path=/tmp/this_is_{{ ansible_hostname }}_file state=touch
          when: (ansible_hostname == "nfs") or (ansible_hostname == "backup")	
    
        - name: install httpd
    	  yum: name=httpd state=installed
    	  when: (系统情况 == "CentOS")
    	  
    	- name: install httpd2
          yum: name=httpd2 state=installed
          when: (系统情况 == "ubuntu") 
    
    获取内置变量方法:
    ansible oldboy -m setup -a "filter=ansible_hostname"
    常见主机信息:
    ansible_all_ipv4_addresses:				仅显示ipv4的信息。
    ansible_devices:							仅显示磁盘设备信息。
    ansible_distribution:						显示是什么系统,例:centos,suse等。
    ansible_distribution_major_version:		显示是系统主版本。
    ansible_distribution_version:				仅显示系统版本。
    ansible_machine:							显示系统类型,例:32位,还是64位。
    ansible_eth0:								仅显示eth0的信息。
    ansible_hostname:							仅显示主机名。
    ansible_kernel:							仅显示内核版本。
    ansible_lvm:								显示lvm相关信息。
    ansible_memtotal_mb:						显示系统总内存。
    ansible_memfree_mb:						显示可用系统内存。
    ansible_memory_mb:							详细显示内存情况。
    ansible_swaptotal_mb:						显示总的swap内存。
    ansible_swapfree_mb:						显示swap内存的可用内存。
    ansible_mounts:							显示系统磁盘挂载情况。
    ansible_processor:							显示cpu个数(具体显示每个cpu的型号)。
    ansible_processor_vcpus:					显示cpu个数(只显示总的个数)。
    
    实践编写:
    [root@m01 ansible_playbook]# cat test_判断功能.yaml 
    - hosts: rsync
      tasks:
        - name: create server password file
          copy: content='rsync_backup:oldboy123' dest=/etc/rsync.password mode=600
          when: (ansible_hostname == "backup")
        - name: create client password file
          copy: content='oldboy123' dest=/etc/rsync.password mode=600
          when: (ansible_hostname != "backup")
  • 相关阅读:
    主从服务器配置与服务----有图
    密钥ssh 配置操作
    用户权限的sudo管理
    系统进程与计划任务管理
    文件系统--磁盘空间耗尽--磁盘坏道 处理以上问题
    MySQL字符串函数:substring_index()的使用详解
    MySQL字符串函数:locate()使用方法详解
    PHP 常用特殊字符的各种表示
    PHP get_headers()函数详解
    PHP urlencode()和urldecode()函数详解
  • 原文地址:https://www.cnblogs.com/yangtao416/p/14593462.html
Copyright © 2020-2023  润新知