Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. # sample of a playbook that just uses localhost for a bunch of AWS tasks
  2.  
  3. ```
  4. ---
  5. - hosts: localhost
  6. tasks:
  7. - name: make a VPC for my app
  8. register: vpc
  9. ec2_vpc:
  10. region: us-west-2
  11. state: present
  12. cidr_block: 172.30.0.0/16
  13. subnets:
  14. - cidr: 172.30.1.0/24
  15. az: us-west-2c
  16. resource_tags: { "Environment":"Dev", "Tier" : "Misc" }
  17. - cidr: 172.30.2.0/24
  18. az: us-west-2a
  19. resource_tags: { "Environment":"Dev", "Tier" : "Main" }
  20. - cidr: 172.30.3.0/24
  21. az: us-west-2b
  22. resource_tags: { "Environment":"Dev", "Tier" : "Reserve" }
  23. internet_gateway: True
  24. route_tables:
  25. - subnets:
  26. - 172.30.1.0/24
  27. - 172.30.2.0/24
  28. - 172.30.3.0/24
  29. routes:
  30. - dest: 0.0.0.0/0
  31. gw: igw
  32. - ec2:
  33. key_name: ryansb
  34. region: us-west-2
  35. instance_type: t2.large
  36. image: ami-d0f506b0
  37. wait: yes
  38. instance_tags:
  39. foo: bar
  40. exact_count: 1
  41. count_tag: foo
  42. assign_public_ip: yes
  43. ```
  44.  
  45. In a normal playbook (executing on a group of remote hosts) if you wanted to interleave tasks going to 3rd parties like AWS, you'd do something like:
  46.  
  47. ```
  48. - file: name=/tmp/something state=file
  49. - ec2:
  50. key_name: ryansb
  51. region: us-west-2
  52. instance_type: t2.large
  53. image: ami-d0f506b0
  54. wait: yes
  55. instance_tags:
  56. foo: bar
  57. exact_count: 1
  58. count_tag: foo
  59. assign_public_ip: yes
  60. delegate_to: localhost
  61. run_once: true
  62. - command: cat /proc/cpuinfo
  63. ```
  64. So that way the file and command tasks run on all hosts, but only one instance is created (by the Ansible master)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement