资产清单:
[demo1] 172.22.32.25 hostname=hostname1 172.22.32.26 hostname=hostname2 172.22.32.27 hostname=hostname3 172.22.32.28 hostname=hostname4 172.22.32.29 hostname=hostname5 172.22.32.30 hostname=hostname6
playbook
--- - hosts: demo1 tasks: - name: 覆盖/etc/hostname文件 raw: 'echo {{ hostname|quote }} > /etc/hostname' - name: 命令再次设置 shell: hostnamectl set-hostname {{ hostname|quote }}标签:ip,hostname,主机名,etc,ansible,playbook,172.22 From: https://www.cnblogs.com/netsa/p/17461321.html