zoukankan      html  css  js  c++  java
  • 【ansible】playbook 主机变量1

    hosts 配置后可以支持指定 端口,密码等其他变量



    [root@10_1_162_39 host_vars]# ll total
    12 -rw-r--r-- 1 root root 236 May 5 09:11 hosts -rw-r--r-- 1 root root 205 May 4 21:08 test1.yaml -rw-r--r-- 1 root root 146 May 5 09:09 test.playbook [root@10_1_162_39 host_vars]# cat hosts [web] 10.1.167.36 [web:vars] ansible_ssh_port=32200 [web1] 10.1.167.18 [web1:vars] ansible_ssh_port=322 [test] 10.1.162.18 ansible_ssh_port=322 ansible_ssh_pass=test*
    10.1.167.36 ansible_ssh_port=32200 ansible_ssh_pass=test***
    [root@10_1_162_39 host_vars]# cat test.playbook 
    ---
    - hosts: test
      gather_facts: false
      remote_user: root
      tasks:
        - shell: ifconfig
          register: output
        - debug: var=output.stdout
    [root@10_1_162_39 host_vars]# ansible-playbook test.playbook -i hosts 
    
    PLAY [test] ********************************************************************
    
    TASK [command] *****************************************************************
    changed: [10.1.162.18]
    changed: [10.1.167.36]
    
    TASK [debug] *******************************************************************
    ok: [10.1.167.36] => {
        "output.stdout": "eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.142.129  netmask 255.255.255.0  broadcast 192.168.142.255
            inet6 fe80::20c:29ff:fe9e:335f  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:9e:33:5f  txqueuelen 1000  (Ethernet)
            RX packets 32739  bytes 2492311 (2.3 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 1943  bytes 231372 (225.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1  (Local Loopback)
            RX packets 4  bytes 340 (340.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 4  bytes 340 (340.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
            ether 52:54:00:2b:6f:35  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0"
    }
    ok: [10.1.162.18] => {
        "output.stdout": "eth0      Link encap:Ethernet  HWaddr 00:0C:29:21:BD:17  
              inet addr:192.168.238.129  Bcast:192.168.238.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe21:bd17/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:299606 errors:0 dropped:0 overruns:0 frame:0
              TX packets:120969 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:363277194 (346.4 MiB)  TX bytes:6698174 (6.3 MiB)
              Interrupt:19 Base address:0x2000 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:8 errors:0 dropped:0 overruns:0 frame:0
              TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:480 (480.0 b)  TX bytes:480 (480.0 b)"
    }
    
    PLAY RECAP *********************************************************************
    10.1.162.18                : ok=2    changed=1    unreachable=0    failed=0   
    10.1.167.36                : ok=2    changed=1    unreachable=0    failed=0   
    
    [root@10_1_162_39 host_vars]# 
  • 相关阅读:
    【SPOJ】6779 Can you answer these queries VII
    【SPOJ】1557 Can you answer these queries II
    【SPOJ】2916 Can you answer these queries V
    【CodeForces】86D Powerful array
    【SPOJ】1043 Can you answer these queries I
    【HDU】3727 Jewel
    【HDU】3915 Game
    【SPOJ】1043 Can you answer these queries III
    【SPOJ】2713 Can you answer these queries IV
    成为一名更好的软件工程师的简单方法
  • 原文地址:https://www.cnblogs.com/lxmhhy/p/6811271.html
Copyright © 2011-2022 走看看