ansible setup 模块

ansible 可以获取被管理机器的很多信息,都是通过ansible 的setup模块来获取的。

  • ansible shell 使用setup模块
# ansible localhost -m setup -a 'filter=ansible_eth0'

# 等等
  • ansible plabook 使用变量获取节点信息
# cat hosts.yml 
---
- name: k8s master 
  hosts: localhost
  remote_user: centos
  become: yes
  become_method: sudo
  vars:
    IP: "{{ ansible_eth0['ipv4']['address'] }}"

  tasks:
  - name: print
    shell: echo ${{IP}} >> /tmp/a

 

其他信息都可以以此类推。

 

posted @ 2018-07-11 19:36  Star-Hitian  阅读(497)  评论(0)    收藏  举报