Use Shell to modify IP aliases for ansbile host files

Source: Internet
Author: User
Tags aliases

#需求

Original content 10.221.29.30 modified: qq1-5f ansible_ssh_host=10.221.29.30

Original content 10.225.32.75 modified: qq6-10f ansible_ssh_host=10.225.32.75

Original content 10.221.249.127 modified: qq11-15f ansible_ssh_host=10.221.249.127


#文件展示

[Email protected] opt]# tree/opt//opt/├──1.txt├──2.txt├──gai.sh└──hosts0 directories, 4 files


#hosts文件

cat/opt/ hosts10.221.29.3010.225.32.7510.221.249.12710.221.29.110.225.37.10010.225.32.6310.221.252.19110.225.32.20510.221.101.1310 .143.94.5910.232.48.16310.232.44.18010.207.161.21610.143.82.8910.225.32.81


#脚本内容

[[email protected] opt]# cat gai.sh #!/bin/bashfor i in  ' cat /opt /hosts ' do        echo  "ansible_ssh_host= $i"  >> / Opt/1.txtdonei=0for b in {1..85}do        er= ' Expr   $b  % 5 '         if [  $er  -eq 0  ];then                yi = ' expr  $b  - 4 '                  let i++                 c= ' head -' $i '  /opt/1.txt | tail -1 '                  echo  "QQ" $yi "-" $b "f  $c"  > > 2.txt  &nBsp;     fidone 


#脚本执行, 1.txt content viewing

[[Email protected] opt]# sh a.sh[[email protected] opt]# cat 1.txt ansible_ssh_host=10.251.132.52ansible_ssh_host= 10.251.124.52ansible_ssh_host=10.221.29.30ansible_ssh_host=10.225.32.75ansible_ssh_host=10.221.249.127ansible_ ssh_host=10.221.29.1ansible_ssh_host=10.225.37.100ansible_ssh_host=10.225.32.63ansible_ssh_host= 10.221.252.191ansible_ssh_host=10.225.32.205ansible_ssh_host=10.221.101.13ansible_ssh_host=10.143.94.59ansible _ssh_host=10.232.48.163ansible_ssh_host=10.232.44.180ansible_ssh_host=10.207.161.216ansible_ssh_host= 10.143.82.89ansible_ssh_host=10.225.32.81


#修改后的配置文件

[email protected] opt]# cat 2.txt qq1-5f ansible_ssh_host=10.251.132.52qq6-10f ansible_ssh_host= 10.251.124.52qq11-15f ansible_ssh_host=10.221.29.30qq16-20f ansible_ssh_host=10.225.32.75qq21-25f Ansible_ssh_ host=10.221.249.127qq26-30f ansible_ssh_host=10.221.29.1qq31-35f ansible_ssh_host=10.225.37.100qq36-40f Ansible_ ssh_host=10.225.32.63qq41-45f ansible_ssh_host=10.221.252.191qq46-50f ansible_ssh_host=10.225.32.205qq51-55f ansible_ssh_host=10.221.101.13qq56-60f ansible_ssh_host=10.143.94.59qq61-65f ansible_ssh_host= 10.232.48.163qq66-70f ansible_ssh_host=10.232.44.180qq71-75f ansible_ssh_host=10.207.161.216qq76-80f Ansible_ssh_ host=10.143.82.89qq81-85f ansible_ssh_host=10.225.32.81

This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1792383

Use Shell to modify IP aliases for ansbile host files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.