bash;gutter:true;
1、定义剧本(我这里只输出序列号)</p>
<pre><code>
;gutter:true;
[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
bash;gutter:true;
2、定义清单</p>
<pre><code>
;gutter:true;
[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任务
bash;gutter:true;
[root@libin3]# ansible-playbook -i hosts task libin.yaml
Original: https://www.cnblogs.com/libin-linux/p/16460812.html
Author: LB_运维技术
Title: Asible 批量跑出服务器相关信息
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/523157/
转载文章受原作者版权保护。转载请注明原作者出处!