Ansible repo for digital ocean projects
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

README.md 7.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # 📗 do-ansible-inventory
  2. do-ansible-inventory is a tool that generates an [Ansible inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html) file with your DigitalOcean Droplets. It is an alternative to [dynamic inventories](https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html#intro-dynamic-inventory) as you can run do-ansible-inventory once and receive a static inventory file that you can use anywhere, copy, or modify.
  3. ## Installation
  4. 1. Download the latest release from [the releases page](https://github.com/do-community/do-ansible-inventory/releases).
  5. 2. Extract the downloaded archive and place the binary `do-ansible-inventory` wherever you like. Preferably to any directory in your `$PATH` such as `~/bin` if it exists or `/usr/local/bin` so you can easily access it.
  6. ## Usage
  7. To use do-ansible-inventory, run:
  8. ```
  9. do-ansible-inventory
  10. ```
  11. By default, without setting any options, do-ansible-inventory will attempt to look up the currently configured [doctl](https://github.com/digitalocean/doctl) access token and generate an ansible inventory with:
  12. * All of your Droplets as Ansible hosts
  13. * Each DigitalOcean region as an Ansible group containing any Droplets in that region
  14. * Each Droplet tag as a group containing any Droplets with that tag
  15. If you do not have `doctl` installed or would like to explicitly specify the access token, run `do-ansible-inventory --access-token ACCESS_TOKEN` or use the `DIGITALOCEAN_ACCESS_TOKEN` environment variable.
  16. The resulting inventory will be printed to the console. You can save it to a file instead by passing `--out inventory` or redirecting the output like so: `do-ansible-inventory > inventory`.
  17. ### Supported Options
  18. * `-t TOKEN`, `--access-token TOKEN` - DigitalOcean API Token - if unset, do-ansible-inventory attempts to use doctl's stored token of its current default context. Alternatively, use the environment variable `DIGITALOCEAN_ACCESS_TOKEN`
  19. * `--ssh-user USER` - sets the `ansible_user` property on the hosts (Droplets)
  20. * `--ssh-port PORT` - sets the `ansible_port` property on the hosts (Droplets)
  21. * `--tag TAG` - limits the inventory to only Droplets with the specified tag
  22. * `--ignore HOSTNAME` - pass a Droplet's hostname to exclude it from the inventory. **This option can be used multiple times**
  23. * `--group-by-region` - create groups for each DigitalOcean region. Default behavior.
  24. * `--no-group-by-region` - do not create groups for each DigitalOcean region.
  25. * `--group-by-tag` - create groups for each Droplet tag. Default behavior.
  26. * `--no-group-by-tag` - do not create groups for each Droplet tag.
  27. * `--group-by-project` - create groups for each Droplet projects. Default behavior.
  28. * `--no-group-by-project` - do not create groups for each Droplet project.
  29. * `--private-ips` - use private Droplet IPs instead of public IPs
  30. * `--out FILE` - write the ansible inventory to this file - if unset, print to stdout
  31. * `--timeout=2m` - timeout for total runtime of the command, defaults to `2m`
  32. ## Example
  33. Running:
  34. ```
  35. $ do-ansible-inventory --out ./inventory
  36. ```
  37. will output:
  38. ```
  39. • no access token provided, attempting to look up doctl's access token
  40. • using doctl access token context=default
  41. • processing droplet=speedtest-ams2.digitalocean.com
  42. • processing droplet=speedtest-nyc2.digitalocean.com
  43. • processing droplet=speedtest-sfo1.digitalocean.com
  44. • processing droplet=speedtest-ams3.digitalocean.com
  45. • processing droplet=speedtest-blr1.digitalocean.com
  46. • processing droplet=speedtest-fra1.digitalocean.com
  47. • processing droplet=speedtest-lon1.digitalocean.com
  48. • processing droplet=speedtest-nyc1.digitalocean.com
  49. • processing droplet=speedtest-nyc3.digitalocean.com
  50. • processing droplet=speedtest-sfo2.digitalocean.com
  51. • processing droplet=speedtest-sgp1.digitalocean.com
  52. • processing droplet=speedtest-tor1.digitalocean.com
  53. • building region group region=ams1
  54. • building region group region=ams2
  55. • building region group region=ams3
  56. • building region group region=blr1
  57. • building region group region=fra1
  58. • building region group region=lon1
  59. • building region group region=nyc1
  60. • building region group region=nyc2
  61. • building region group region=nyc3
  62. • building region group region=sfo1
  63. • building region group region=sfo2
  64. • building region group region=sfo3
  65. • building region group region=sgp1
  66. • building region group region=tor1
  67. • building tag group tag=speedtests
  68. • done!
  69. ```
  70. with the resulting file `inventory` containing:
  71. ```
  72. speedtest-ams2.digitalocean.com ansible_host=188.226.175.227
  73. speedtest-nyc2.digitalocean.com ansible_host=192.241.184.88
  74. speedtest-sfo1.digitalocean.com ansible_host=107.170.223.15
  75. speedtest-ams3.digitalocean.com ansible_host=178.62.216.76
  76. speedtest-blr1.digitalocean.com ansible_host=139.59.80.215
  77. speedtest-fra1.digitalocean.com ansible_host=46.101.218.147
  78. speedtest-lon1.digitalocean.com ansible_host=46.101.44.214
  79. speedtest-nyc1.digitalocean.com ansible_host=165.227.194.167
  80. speedtest-nyc3.digitalocean.com ansible_host=174.138.51.137
  81. speedtest-sfo2.digitalocean.com ansible_host=165.227.29.84
  82. speedtest-sgp1.digitalocean.com ansible_host=159.89.192.182
  83. speedtest-tor1.digitalocean.com ansible_host=159.203.57.38
  84. [ams1]
  85. [ams2]
  86. speedtest-ams2.digitalocean.com
  87. [ams3]
  88. speedtest-ams3.digitalocean.com
  89. [blr1]
  90. speedtest-blr1.digitalocean.com
  91. [fra1]
  92. speedtest-fra1.digitalocean.com
  93. [lon1]
  94. speedtest-lon1.digitalocean.com
  95. [nyc1]
  96. speedtest-nyc1.digitalocean.com
  97. [nyc2]
  98. speedtest-nyc2.digitalocean.com
  99. [nyc3]
  100. speedtest-nyc3.digitalocean.com
  101. [sfo1]
  102. speedtest-sfo1.digitalocean.com
  103. [sfo2]
  104. speedtest-sfo2.digitalocean.com
  105. [sfo3]
  106. [sgp1]
  107. speedtest-sgp1.digitalocean.com
  108. [tor1]
  109. [speedtests]
  110. speedtest-ams2.digitalocean.com
  111. speedtest-nyc2.digitalocean.com
  112. speedtest-sfo1.digitalocean.com
  113. speedtest-ams3.digitalocean.com
  114. speedtest-blr1.digitalocean.com
  115. speedtest-fra1.digitalocean.com
  116. speedtest-lon1.digitalocean.com
  117. speedtest-nyc1.digitalocean.com
  118. speedtest-nyc3.digitalocean.com
  119. speedtest-sfo2.digitalocean.com
  120. speedtest-sgp1.digitalocean.com
  121. speedtest-tor1.digitalocean.com
  122. ```
  123. ---
  124. ```
  125. usage: do-ansible-inventory [<flags>]
  126. Flags:
  127. -t, --access-token=ACCESS-TOKEN
  128. DigitalOcean API Token - if unset, attempts to use doctl's stored token of its current default context. env var:
  129. DIGITALOCEAN_ACCESS_TOKEN
  130. --ssh-user=SSH-USER default ssh user
  131. --ssh-port=SSH-PORT default ssh port
  132. --tag=TAG filter droplets by tag
  133. --ignore=IGNORE ... ignore a Droplet by name, can be specified multiple times
  134. --group-by-region group hosts by region, defaults to true
  135. --group-by-tag group hosts by their Droplet tags, defaults to true
  136. --group-by-project group hosts by their Projects, defaults to true
  137. --private-ips use private Droplet IPs instead of public IPs
  138. --out=OUT write the ansible inventory to this file - if unset, print to stdout
  139. --timeout=2m timeout for total runtime of the command, defaults to 2m
  140. ```