Is there a way to add new aws regions to Ansible ec2 module, which still uses old boto? - amazon-ec2

Old boto is used in ansible aws ec2 module, which is outdated. last commit 2018y. How do u provision instances in new regions?
my current version of ansible 2.9.6, but in 2.10 & 2.11 changelog there are nothing about chenge to boto3
region list in boto:
[eu-west-1, eu-west-2, cn-north-1, us-east-2, us-gov-west-1, ca-central-1, ap-southeast-2, us-west-2, ap-southeast-1, us-east-1, sa-east-1, us-west-1, ap-northeast-2, eu-central-1, ap-south-1, ap-northeast-1]
region list using boto3:
['af-south-1', 'ap-east-1', 'ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'eu-central-1', 'eu-north-1', 'eu-south-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'me-south-1', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']

Here is a quote from https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_module.html
Note: This module uses the older boto Python module to interact with the EC2 API. amazon.aws.ec2 will still receive bug fixes, but no new features. Consider using the amazon.aws.ec2_instance module instead.

Related

how to make ansible work on remote servers which has python 2.4

Making my question more meaningful...
Ansible controller server :
ansible 2.4.2.0
Python 2.7.5
Managed nodename (goldville):
Python 2.4.2
When i run #ansible goldville -m ping
I get the below error
File "/tmp/ansible_RSjze6/ansible_module_ping.py", line 8\r\n from future import absolute_import, division, print_function\r\nSyntaxError: future feature absolute_import is not defined\r\n"
How can i use this node with python 2.4.2 to run playbooks from controller.
[py24-hosts]
goldville-py3 ansible_host=goldville
[py23-hosts:vars]
ansible_python_interpreter=/usr/bin64/python2.4
When i run below it gave error
#ansible goldville -m ping
Failed to parse /home/ansible/ansiblehosts with ini plugin: /home/ansible/ansiblehosts:4: Section [py23-hosts:vars] not valid
for undefined group: py23-hosts
If you want use python 2.4 some hosts or groups, set the ansible_python_interpreter inventory variable, try something like this:
[py24-hosts]
goldville-py3 ansible_host=goldville
[py24-hosts:vars]
ansible_python_interpreter=/usr/bin64/python2.4
But if you want use python2.4 for all you must set interpreter_python key in the defaults section in the configuraion file ansible.cfg
Docuementation:
https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

Provision EC2 machine in needed packages via CDK

Is it possible to initialize EC2 machine in CDK with needed packages?
Or only way is to create it first and then install needed packages?
Thank you for your answers an tips,
The UserData can run the cfn-init script which will pull down Metadata passed in from CloudFormation, In CDK, this can be done in one object with the CloudFormationInit class
From the CDK documentation - https://docs.aws.amazon.com/cdk/api/latest/docs/aws-ec2-readme.html#configuring-instances-using-cloudformation-init-cfn-init
adding the init param into your aws_ec2.Instance definition (for python similar to)
aws_ec2.Instance(self, scope, ...
init=aws_ec2.CloudFormationInit.from_config_sets(
config_sets={'default': ['init']},
configs={
'init': aws_ec2.InitConfig([
aws_ec2.InitPacakge.python(package_name='boto3'),
aws_ec2.InitFile.from_asset('/usr/local/myscript.sh', 'scripts/myscript.sh')
])
}
), ...
)
this will result in the EC2 instance having the appropriate cfn-init scripting in the UserData section automatically, and load the scripts/myscript.sh into the instance with the boto3 python package installed.
More information on AWS::CloudFormation::Init - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html
I think you are looking for UserData: https://docs.aws.amazon.com/cdk/api/latest/docs/#aws-cdk_aws-ec2.Instance.html#userdata
With UserData you can add commands which your EC2 Instance executes at (by default only first) launch.
E.g. for installing apache:
const userData = ec2.UserData.forLinux();
userData.addCommands('yum install -y httpd');
new ec2.Instance(this, 'instance', {
userData: userData,
...
});
Another way would be to create a custom AMI which you use to start your EC2 instance. That AMI could have all packaged pre-installed.

Getting data from AWS SSM Parameter Store in ruby script using aws-sdk-v1

I'm trying to get the secrets from SSM Parameter store. The issue is we're on aws-sdk-v1 (ruby). For V2, V3 I can get plenty of examples, but not for V1. e.g. code snippet for aws-sdk--v2.
ssm_client = Aws::SSM::Client.new(
region: region
)
param_response = ssm_client.get_parameter(
name: parameter_id,
with_decryption: true
).to_h
Do anyone know how to do it if I'm on aws-sdk-v1.
PS: Upgrading from aws-sdk V1 to V2/V3 is not the viable options, please suggest considering the solution should run on aws-sdk-v1.
Ruby version: '1.9.3'
SSM is already present in the aws-sdk-v1.
There was a dependency issue in my Gemfile. I was using aws-sdk-resources ~> 3, which is fundamentally incompatible with aws-sdk ~> 1.

Chef aws driver tags don't work using Etc.getlogin

I am currently using Chef solo on a Windows machine. I used the fog driver before which created tags for my instances on AWS. Recently, I moved to the aws driver and noticed that aws driver does not handle tagging. I tried writing my own code to create the tags. One of the tags being "Owner" which tells me who created the instance. For this, I am using the following code:
def get_admin_machine_options()
case get_provisioner()
when "cccis-environments-aws"
general_machine_options = {ssh_username: "root",
create_timeout: 7000,
use_private_ip_for_ssh: true,
aws_tags: {Owner: Etc.getlogin.to_s}
}
general_bootstrap_options = {
key_name: KEY_NAME,
image_id: "AMI",
instance_type: "m3.large",
subnet_id: "subnet",
security_group_ids: ["sg-"],
}
bootstrap_options = Chef::Mixin::DeepMerge.hash_only_merge(general_bootstrap_options,{})
return Chef::Mixin::DeepMerge.hash_only_merge(general_machine_options, {bootstrap_options: bootstrap_options})
else
raise "Unknown provisioner #{get_setting('CHEF_PROFILE')}"
end
end
machine admin_name do
recipe "random.rb"
machine_options get_admin_machine_options()
ohai_hints ohai_hints
action $provisioningAction
end
Now, this works fine on my machine. The instance is created on my machine with proper tags but when I run the same code on someone else's machine. It doesn't create the tags at all. I find this to be very weird. Does anyone know what's happening? I have the same code!
Okay so I found the issue. I was using the gem chef-provisioning-aws 1.2.1 and everyone else was on 1.1.1
the gem 1.1.1 does not have support for tagging so it just went right past it.
I uninstalled the old gem and installed the new one. It worked like a charm!

Use Puppet Apache class to install Apache1 on CentOS

I'm trying to create a Vagrant setup using CentOS 6.4 and Apache 1.3 (this is for a legacy application). I am using Puppet (though if an answer in Chef is easier, I'd be happy to use it) and the Puppetlabs Apache class. The issue I'm having is that it installs Apache 2.2, but I don't see how to make it install Apache 1.3 instead.
What am I doing wrong and how can I do it right? (Answers of "Upgrade your app" will be downvoted - I don't have the authority to make that decision.)
The module you're using doesn't explicitly expose a parameter to specify which version of the httpd package you want to install.
Instead of using Puppetlabs module, you could use the Apache module from Alessandro Franceschi (source here - also on the forge)). If the package you need to install has a different name than httpd, the module exposes a package parameter which you can override like this:
class { 'apache':
package => 'apache13',
}
If, instead, Apache 1.3 is provided by the same httpd package by declaring the specific version you want, you can rely on the version parameter:
class { 'apache':
version => '1.3.39',
}
Clearly, you can also combine the two parameters together.
using those modules return the following error on Redhat:
Error 400 on SERVER: Illegal expression.
A Type-Name is unacceptable as function name in a Function Call at /etc/puppet/modules/apache/man.

Resources