0

我想用 Ansible 更改 debian9 ( /etc/network/interfaces ) 中服务器的网络掩码。
你知道我该怎么做吗?

4

1 回答 1

0

直接使用以下剧本。

  [rohtash@172 blockinfile]$ cat edit_netmask.yml 
 
   - hosts: localhost
      connection: local
      tasks:
      - replace:
               path: netmasks
               regexp: 'netmask 255.255.255.0'
               replace: 'netmask {{ input }}'
               backup: yes


[rohtash@172 blockinfile]$ ansible-playbook edit_netmask.yml -e input=255.255.255.240

PLAY [localhost] ******************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************
ok: [localhost]

TASK [replace] ********************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

它将直接替换服务器的网络掩码。

于 2021-03-26T09:25:25.237 回答