zoukankan      html  css  js  c++  java
  • ansible-playbook 修改主机的host解析

    ansible-playbook 修改主机的host解析

    注:ansible 主机同被控主机的互信配置忽略,不在本次讨论的范围内。

    1、增加ansible host被控主机信息

    [root@ansible-server ansible_playbook_temple]# more ansiblehosts 
    [ansible_hosts]
    192.168.1.10
    192.168.1.11
    192.168.1.12
    192.168.1.13
    192.168.1.14
    

    2、测试是否正常

    [root@ansible-server ansible_playbook_temple]#ansible ansible_hosts -i ansiblehosts -m ping
    192.168.1.10 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.1.11 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.1.12 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.1.13 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.1.14 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    

    3、操作被控主机的host解析,通过ansible-playbook

    增加host解析脚本

    [root@ansible-server ansible_playbook_temple]# more add_hosts.yaml 
    ---
    - hosts: ansible_hosts
      remote_user: root
      tasks: 
      - name: add hosts
        lineinfile:
         path: /etc/hosts
         state: present
         line: "10.10.10.100 www.wanghengzhi.com"
      - name: test hosts
        shell: ping -c2 www.wanghengzhi.com
        register: result
        failed_when: false
      - name: "show result"
        debug:
         msg: "{{result.stdout_lines}}"
    

    运行方式

    [root@ansible-server ansible_playbook_temple]#ansible-playbook add_hosts.yaml -i ansiblehosts 
    

    回显内容略过

    修改host解析脚本

    [root@ansible-server ansible_playbook_temple]# more replace_hosts.yaml 
    ---
    - hosts: ansible_hosts
      remote_user: root
      tasks: 
      - name: replace hosts
        lineinfile:
         path: /etc/hosts
         regexp: "10.10.10.100 www.wanghengzhi.com"
         line: "#10.10.10.100 www.wanghengzhi.com"
      - name: test hosts
        shell: ping -c2 www.wanghengzhi.com
        register: result
        failed_when: false
      - name: "show result"
        debug:
         msg: "{{result.stdout_lines}}"

    运行方式

    [root@ansible-server ansible_playbook_temple]#ansible-playbook replace_hosts.yaml -i ansiblehosts 

    回显内容略过

    删除host解析脚本

    [root@ansible-server ansible_playbook_temple]# more del_hosts.yaml 
    ---
    - hosts: ansible_hosts
      remote_user: root
      tasks: 
      - name: del hosts
        lineinfile:
         path: /etc/hosts
         state: absent
         line: "10.10.10.100 www.wanghengzhi.com"
      - name: test hosts
        shell: ping -c2 www.wanghengzhi.com
        register: result
        failed_when: false
      - name: "show result"
        debug:
         msg: "{{result.stdout_lines}}"

    运行方式

    [root@ansible-server ansible_playbook_temple]#ansible-playbook del_hosts.yaml -i ansiblehosts 

    回显内容略过

  • 相关阅读:
    20120110 自己写的基于jquery的翻页效果
    搜来的 可爱的if ie
    哎~~~纠结死了的终于解决的i6的fixed属性
    2011815发现可好的js繁简转换代码 写这些的人。。好厉害呀 收藏了~~~
    网站制作CSS图片转换滤镜代码(貌似只对ie有用。。。)
    2011811 右下角弹出渐隐的广告代码 可以关闭 可以缩小 还各种兼容(ff opera ie6、7、8都试过了)值得保留哎~~~
    20120604 自己写的基于jquery的类似百度贴吧头像提示效果
    UFT textUtil object 解决奇怪问题
    UFT send request & get response
    UFT connect sql (1)
  • 原文地址:https://www.cnblogs.com/xzlive/p/14086438.html
Copyright © 2011-2022 走看看