Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- ### Bring the hosts module into the library directory:
- # mkdir library
- # curl -o library/etc_hosts.py https://raw.githubusercontent.com/jtyr/ansible/ansible-modules-extras/pull/3457/lib/ansible/modules/system/etc_hosts.py
- ### Run the playbook:
- # ansible-playbook -i localhost, --diff site.yaml
- - name: Testing hosts module
- hosts: localhost
- gather_facts: no
- connection: local
- tasks:
- - name: Add a new record without alias
- etc_hosts:
- ip: 10.0.0.1
- hostname: some.domain1.com
- path: /tmp/hosts
- - name: Add a new record with hostname for the same IP
- etc_hosts:
- ip: 10.0.0.1
- hostname: some.domain2.com
- path: /tmp/hosts
- - name: Add a new record with another IP for the same hostname
- etc_hosts:
- ip: 10.0.0.2
- hostname: some.domain3.com
- path: /tmp/hosts
- - name: Add a new record with hostname and alias for the same IP
- etc_hosts:
- ip: 10.0.0.3
- hostname: some.domain3.com
- alias: some
- path: /tmp/hosts
- - name: Add a new record with multiple aliases
- etc_hosts:
- ip: 10.0.0.4
- hostname: some.domain4.com
- alias:
- - some
- - other
- path: /tmp/hosts
- - name: Update the list of aliases for the existing IP and hostname
- etc_hosts:
- ip: 10.0.0.4
- hostname: some.domain4.com
- alias:
- - some
- - other
- - alias
- path: /tmp/hosts
- - name: Remove all records with the specified IP
- etc_hosts:
- ip: 10.0.0.1
- state: absent
- path: /tmp/hosts
- - name: Remove all records with the specified hostname
- etc_hosts:
- hostname: some.domain3.com
- state: absent
- path: /tmp/hosts
- - name: Remove record with specified IP and hostname
- etc_hosts:
- ip: 10.0.0.4
- hostname: some.domain4.com
- state: absent
- path: /tmp/hosts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement