Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The script generates the ansible host inventory host list in batch.

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Windows's vars does not take effect in the hosts file, so I write a script to add hosts in batches, lazy to spend time looking for information.

Every time the government cloud pushes the host, a new host inventory file is generated. The template password is the same, and the ip stores the list.txt file.

#! / bin/bashread-p "Please enter the system version [windows/linux]:" versioncase $version in windows) echo "[windows]" > / etc/ansible/hosts for ip in `cat list.txt` do echo "$ip ansible_ssh_user=" Administrator "ansible_ssh_pass=" template password "ansible_ssh_" Port=5985 ansible_connection= "winrm" ansible_winrm_server_cert_validation=ignore "> > / etc/ansible/hosts done echo" / etc/ansible/hosts file created successfully "cat / etc/ansible/hosts" Linux) echo "[linux]" > / etc/ansible/hosts for ip in `cat list.txt` do echo "$ip ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=' template password'" > > / etc/ansible/hosts done echo "/ etc/ansible/hosts file created successfully" cat / etc/ansible/hosts ; *) echo "Please enter system version [windows/linux]" esac

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report