Comments (2)
in vultr we implemented 2 types: inventory plugin and module (task plugin).
🤯
Thank you very much for pointing me in the right direction. I would like to avoid setting the environment variable for the VULTR_API_KEY
as I would like to keep it encrypted within ansible.
This is what I ended up with (for now)
.
├── roles
│ └── common
│ ├── tasks
│ │ └── main.yaml
│ └── vars
│ └── main.yaml
└── site.yaml
roles/common/tasks/main.yaml
---
- name: Setting Vars
ansible.builtin.include_vars: main.yaml
- name: Gather Vultr regions information
vultr.cloud.region_info:
api_key: "{{ api_key }}"
register: region
- name: Print syd region information
ansible.builtin.debug:
var: "{{ region }}"
loop: "{{ region.vultr_region_info }}"
when:
- item.country == "AU"
- item.id == "syd"
roles/common/vars/main.yaml
---
plugin: vultr.cloud.vultr
api_key: abc123
compose:
ansible_host: vultr_main_ip
site.yaml
- name: Main Play
hosts: localhost
roles:
- { role: common, tags: always }
And I call it with
ansible-playbook site.yaml
I can confirm the api_key
variable gets carried across multiple roles.
Thank you once again for you help.
from ansible-collection-vultr.
Hi @Hickory420
Ansible has a few plugin types, in vultr we implemented 2 types: inventory plugin and module (task plugin).
The config in ./vultr.yaml, e.g.
plugin: vultr.cloud.vultr
api_key: your key
is only for the inventory plugin, further you would need to enable this plugin in your ansible.cfg
in your project roots direcotory:
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml, vultr.cloud.vultr
To test it, you could run:
ansible-inventory -i vultr.yml --list
and you should get a list of all vultr instances, to test connection, you have to tell the plugin how to connect to the instances if you don't want to use the label name as a DNS target (this is in the docs of the plugin ansible-doc -t inventory vultr.cloud.vultr
)
plugin: vultr.cloud.vultr
api_key: your key
compose:
ansible_host: vultr_main_ip
after that you will be able to "ping" (ssh into your VMs and test connection) using:
ansible -m ping -i vultr.yml -u root all
If you want to use the modules to create instances, see plans, regions and so on, the API key must be provided again (https://docs.ansible.com/ansible/latest/collections/vultr/cloud/region_info_module.html#parameter-api_key) to this plugin type. This could be achieved in few different ways (not vultr specific) but one way would be to put it into a group_vars
variable and pass it in the tasks as an argument:
---
- name: View the regions
hosts: localhost
vars:
# this would go into group_vars/all.yml
vultr_api_key: my key
tasks:
- name: Gather Vultr regions information
vultr.cloud.region_info:
api_key: "{{ vultr_api_key }}"
register: region
- name: Print the gathered information
ansible.builtin.debug:
var: result.vultr_region_info
NOTE: Another way to provide the vultr api key to all plugin types is using an environment variable:
$ export VULTR_API_KEY=my key
ansible-inventory -i vultr.yml --list
I hope my explanation solved the issue.
from ansible-collection-vultr.
Related Issues (20)
- [Feature] - Object Storage HOT 1
- [BUG] - Wrong name-label alias in instance_info module
- [Feature] - Container Registry support
- [BUG] - traceback in CI tests
- [Missing] - VPC 2.0 parameter HOT 1
- [BUG] - instance absent fails with "Server is currently locked"
- [Feature] - Option to skip waiting for instance creation HOT 2
- [Feature] State `reinstalled` HOT 1
- [Bug] vultr_tags not returned in inventory HOT 4
- [Feature] - Ability to Reboot Instance(s) HOT 1
- Typo in `instance_info` examples
- [BUG] - Idempotence check fails in vultr.cloud.firewall_rule when ICMP has port HOT 3
- [Feature] - bare metal support HOT 2
- [BUG] - Weird 401 error
- [BUG] - Useless shebangs HOT 5
- [BUG] - internal_ip no longer shows up with ansible-inventory --list HOT 6
- [Feature] - vultr_gateway_v4 not set in hostvars; gateway_v4 appears in vultr.cloud.instance_info HOT 4
- [BUG] - module "reserved_ip" crashes when adding new reserved IP HOT 2
- [Feature] - automatic private network set up with enable_vpc: true|false HOT 6
- Add "user_schema" as parameter in instance module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-collection-vultr.