Asible 批量跑出服务器相关信息

1
1、定义剧本(我这里只输出序列号)<br><br>
1
2
3
4
5
6
7
8
9
10
11
12
[root@libin3]# cat libin.yml
- hosts: task
  gather_facts: no
  tasks:
    - name: fetch
      shell: |
        dmidecode -t 1 | grep "Serial Number" | awk -F ":" '{print $2}'
      register: serial
    - name: dd
      shell: |
        echo "{{serial.stdout}},{{inventory_hostname}}" >> libin.csv
      delegate_to: localhost
1
2、定义清单<br><br>
1
2
3
4
5
6
7
8
9
10
11
12
<br>[root@libin3]# cat hosts
 
[task]
ip地址
 
[task:vars]
ansible_become=yes
ansible_become_method=sudo
ansible_become_user=root
ansible_become_password=
ansible_user=
ansible_password=

3、执行ansible任务

1
[root@libin3]# ansible-playbook -i hosts task libin.yaml

  

posted @   LB_运维技术  阅读(53)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示