Ansible
› Ansible Documentation
zealinux
V2EX  ›  Ansible

ansbile 怎么把连接的目标 HOST IP 通过变量传递过去

  •  
  •   zealinux · Dec 29, 2020 · 3190 views
    This topic created in 2137 days ago, the information mentioned may be changed or developed.

    比如:ansible-playbook 新建一个任务,

    就是把目标 IP 加到目标机器的环境变量中。 主要不知道该怎么传递这个变量。

    6 replies  •  2020-12-29 14:20:03 +08:00
    xcai
    xcai
    Dec 29, 2020
    1
    ansible_facts {{ ansible_facts['default_ipv4']['address'] }}如果是机器去取其它机器的 IP 再加上 {{ hostsvars[机器名] ansible_facts['default_ipv4']['address'] }} 具体查一下,不知道有无记错。
    David1119
    David1119
    Dec 29, 2020
    2
    命令:ansible-playbook xxx.yaml --extra-vars "your_vars=aaaa"

    在 xxx.yaml 里面直接用 {{your_vars}}
    zealinux
    zealinux
    OP
    Dec 29, 2020
    3
    @David1119 aaa 是什么?

    这个是动态的,是连的那个 host,就是那台 ansible_host
    ik
    ik
    Dec 29, 2020
    4
    {{ansible_ssh_host}}
    ik
    ik
    Dec 29, 2020
    5
    ```
    [root@un~]# ansible all -m debug -a "msg={{ansible_ssh_host}}"
    45.153.x.x | SUCCESS => {
    "msg": "45.153.x.x"
    }
    109.166.x.x | SUCCESS => {
    "msg": "109.166.x.x"
    }
    ```
    zealinux
    zealinux
    OP
    Dec 29, 2020
    6
    @ik bingo
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1902 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:35 · PVG 00:35 · LAX 08:35 · JFK 11:35
    ♥ Do have faith in what you're doing.