I want to create variable number of EC2 instances within my cloudformation template (YAML).
I am planning to create a stack for EC2 instance creation and loop the same.
I read this is achievable using Troposphere.
Can someone help me with a template or example?
Write the below into a class you can reuse for each instance.
https://github.com/cloudtools/troposphere/blob/master/examples/EC2InstanceSample.py
Related
Creating surveys is pretty straightforward, as is using their results in templates/jobs. However, I am finding that I have a survey that I keep having to recreate. Is it possible to create one that could then be re-used across multiple templates?
What you could do is that you could use the controller/tower/awx collection, and from that the job_template module, which has a survey_spec option.
In other words: you could create a playbook/job template, that updates/creates other job templates and adds the survey.
Here the module: https://docs.ansible.com/ansible/latest/collections/awx/awx/job_template_module.html#ansible-collections-awx-awx-job-template-module
...and here's how to define the survey_spec: https://docs.ansible.com/automation-controller/latest/html/controllerapi/api_ref.html#/Job_Templates/Job_Templates_job_templates_survey_spec_list
With this you practically automate your tower/controller/awx config.
I've dipped my toe in chef and am having a few difficulties with what should be simple concepts.
I'm obtains data from a node by running a search; my plan is to iterate over the results and create an object of type X setting its variables as I go.
I'd like to store these objects in a collection so that I can access them later in the recipe to carry out other tasks and so on.
My GoogleFu has so far come up short and I'm worried that I'm tackling this in the wrong way. My search is fine and returning the values, my separate class is also fine but the storing of these objects into a collection and then persisting that is proving more difficult. Many posts frown against using arrays for my purpose(if it's possible) and I've not found anything similar to an ArrayList or Map. Additionally, if I use a ruby collection, does it need to be maintained inside a ruby block?
Thanks for any help / advice.
With Chef, you have several ways of storing persistent data:
1) set node attributes
2) chef data bags
3) chef vault
4) environments
5) environment recipes
6) roles
IMHO, you should decide where this data should reside by determining which of the items I listed it belongs to.
What does it apply to? What does it describe?
You got to be more specific in where you are actually facing the issue but as far as I have understood why not
just define a ruby class and initialize all the variables you are supposed to get. In the recipe instantiate the object and keep settings its properties from the result. There should be no issue in this approach.
But more importantly what is your use-case here, because you could just define an array attribute and then keep syncing the result in that attribute . As in ruby Objects are referenced , thus any change you make to resource attributes which takes that object, changes are persistent to in that object.
I have a requirement where we should be creating for Factories for servers, we call them as Vservers. It basically has the attributes like Fully qualified domain name (fqdn), eg: dev-vserver.storage.com, ID and etc..
We make a connection to the Vserver and retrieve information about different operations that we do like provisioning storage, resizing of volumes, deletion of volumes etc., in a json format.
We would like to come up with a better unit testing environment with RSPEC and FactoryGirl, where we can mock the Vserver functionality by creating doubles or mocks instead of directly interacting with the actual Vserver for testing.
I would like to hear suggestions and opinions from all you.
Help is much appreciated.
Thanks,
Mahesh
So from what I gather, you want to use mocks or test doubles to mimic the functionality of your Vservers. This is indeed possible, the question is should it be done.
You can use factory girl to create factories for each of your Vserver classes, but those facotories will only return whatever data you give them, they wont have any real data, since they only have whatever you assigned them in your tests or factories.
What I would recommend is that within your facotries, you actually establish a connection to each instance of your Vservers, and pull back all the attributes which you need. So for example you could create a factory like so:
factory :vserver_1 do
id { connect_to_vserver_1_and_get_id }
domain_name { connect_to_vserver_1_get_domain_name }
end
This would instantiate a new instance of vserver_1, with all the attributess of your current vserver. If you were to change the domain name of verserver 1 in the future, your vserver_1 factory would reflect these changes.
Also, the factory girl gem has great docs, you should definitely read them in their entirety before building a new test suite. Good luck!
I wanted to ask what operations should be pleaced in ConstructUsing and what in WhenStarted. In fact things which normally are placed in contructor like configuration read, initialization in case of service should be placed in WhenStarted IMO in order to refresh all things during service restart, so what is left for ConstructUsing? just newing up the class and that's all? But in that case why not newing up in WhenStarted as well?
Thanks in advance
ConstructUsing defines how to create your service, which can indeed just be a new(), or alternatively another way of obtaining the service:
For example, using IoC:
// Release in WhenStopped()
sc.ConstructUsing(() => container.Resolve<IMyService>());
Another option is to use an existing instance of the service:
sc.ConstructUsing(() => serviceInstance);
WhenStarted, on the other hand, defines what actions to take when the instance of the service starts, and so requires an instance to configure: you wouldn't be able to create the service here:
sc.WhenStarted(service => service.Start());
while learning Rails, I keep hearing Local vs Instance but I can't find a definition of the two & the differences. And I'd like to avoid making assumptions.
What are the two and how are they different?
Thanks
The main difference between local and instance variable is that local variable is only available in controller, where as instance variable is available in corresponding views also. The controller and views do not share local variables.
Thanks, Anubhaw
The main differences between local and instance variables are as follows
local variable has its scope restriction i.e not available to another methods where as instance available to another
local and instance variable is also available in view
instance variable is separate for each object