Advertisement
jtyr

site.yaml

Nov 15th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.99 KB | None | 0 0
  1. ---
  2.  
  3. ### Bring the hosts module into the library directory:
  4. # mkdir library
  5. # curl -o library/etc_hosts.py https://raw.githubusercontent.com/jtyr/ansible/ansible-modules-extras/pull/3457/lib/ansible/modules/system/etc_hosts.py
  6.  
  7. ### Run the playbook:
  8. # ansible-playbook -i localhost, --diff site.yaml
  9.  
  10. - name: Testing hosts module
  11.   hosts: localhost
  12.   gather_facts: no
  13.   connection: local
  14.   tasks:
  15.     - name: Add a new record without alias
  16.       etc_hosts:
  17.         ip: 10.0.0.1
  18.         hostname: some.domain1.com
  19.         path: /tmp/hosts
  20.  
  21.     - name: Add a new record with hostname for the same IP
  22.       etc_hosts:
  23.         ip: 10.0.0.1
  24.         hostname: some.domain2.com
  25.         path: /tmp/hosts
  26.  
  27.     - name: Add a new record with another IP for the same hostname
  28.       etc_hosts:
  29.         ip: 10.0.0.2
  30.         hostname: some.domain3.com
  31.         path: /tmp/hosts
  32.  
  33.     - name: Add a new record with hostname and alias for the same IP
  34.       etc_hosts:
  35.         ip: 10.0.0.3
  36.         hostname: some.domain3.com
  37.         alias: some
  38.         path: /tmp/hosts
  39.  
  40.     - name: Add a new record with multiple aliases
  41.       etc_hosts:
  42.         ip: 10.0.0.4
  43.         hostname: some.domain4.com
  44.         alias:
  45.          - some
  46.           - other
  47.         path: /tmp/hosts
  48.  
  49.     - name: Update the list of aliases for the existing IP and hostname
  50.       etc_hosts:
  51.         ip: 10.0.0.4
  52.         hostname: some.domain4.com
  53.         alias:
  54.          - some
  55.           - other
  56.           - alias
  57.         path: /tmp/hosts
  58.  
  59.     - name: Remove all records with the specified IP
  60.       etc_hosts:
  61.         ip: 10.0.0.1
  62.         state: absent
  63.         path: /tmp/hosts
  64.  
  65.     - name: Remove all records with the specified hostname
  66.       etc_hosts:
  67.         hostname: some.domain3.com
  68.         state: absent
  69.         path: /tmp/hosts
  70.  
  71.     - name: Remove record with specified IP and hostname
  72.       etc_hosts:
  73.         ip: 10.0.0.4
  74.         hostname: some.domain4.com
  75.         state: absent
  76.         path: /tmp/hosts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement