Skip to content

Commit 72e2503

Browse files
author
nadeemshahzad
committed
fix: mongo role for sandbox
1 parent 11faee4 commit 72e2503

File tree

12 files changed

+133
-76
lines changed

12 files changed

+133
-76
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ requirements:
2020
pip install -qr requirements/pip.txt --exists-action w
2121
pip install -qr requirements.txt --exists-action w
2222

23+
requirements3_12:
24+
pip install -qr requirements/pip.txt --exists-action w
25+
pip install -qr requirements3_12txt --exists-action w
26+
27+
2328
COMMON_CONSTRAINTS_TXT=requirements/common_constraints.txt
2429
.PHONY: $(COMMON_CONSTRAINTS_TXT)
2530
$(COMMON_CONSTRAINTS_TXT):

playbooks/edx_provision.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
wait_for:
6262
path: /var/log/cloud-init.log
6363
timeout: 15
64-
search_regex: "final-message"
64+
search_regex: "final[-_]message"
6565
- name: gather_facts
6666
setup: ""
6767
vars_files:

playbooks/library/ec2_lookup

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
from __future__ import absolute_import
1818
from __future__ import print_function
19-
import six
19+
import sys
20+
import boto3
21+
from ansible.module_utils.basic import AnsibleModule
22+
2023
DOCUMENTATION = '''
2124
---
2225
module: ec2_lookup
@@ -28,8 +31,8 @@ options:
2831
region:
2932
description:
3033
- The AWS region to use. Must be specified if ec2_url
31-
is not used. If not specified then the value of the
32-
EC2_REGION environment variable, if any, is used.
34+
is not used. If not specified then the value of
35+
the EC2_REGION environment variable, if any, is used.
3336
required: false
3437
default: null
3538
aliases: [ 'aws_region', 'ec2_region' ]
@@ -42,20 +45,20 @@ options:
4245
aliases: [ 'ec2_secret_key', 'secret_key' ]
4346
aws_access_key:
4447
description:
45-
- AWS access key. If not set then the value of the
46-
AWS_ACCESS_KEY environment variable is used.
48+
- AWS access key. If not set then the value of
49+
the AWS_ACCESS_KEY environment variable is used.
4750
required: false
4851
default: null
4952
aliases: [ 'ec2_access_key', 'access_key' ]
5053
tags:
51-
desription:
54+
description:
5255
- tags to lookup
5356
required: false
5457
default: null
5558
type: dict
5659
aliases: []
5760
58-
requirements: [ "boto" ]
61+
requirements: [ "boto3" ]
5962
author: John Jarvis
6063
'''
6164

@@ -70,8 +73,6 @@ EXAMPLES = '''
7073
Name: foo
7174
'''
7275

73-
import sys
74-
7576
AWS_REGIONS = ['ap-northeast-1',
7677
'ap-southeast-1',
7778
'ap-southeast-2',
@@ -81,17 +82,8 @@ AWS_REGIONS = ['ap-northeast-1',
8182
'us-west-1',
8283
'us-west-2']
8384

84-
try:
85-
import boto.ec2
86-
from boto.ec2 import connect_to_region
87-
except ImportError:
88-
print("failed=True msg='boto required for this module'")
89-
sys.exit(1)
90-
91-
9285
def main():
93-
94-
module=AnsibleModule(
86+
module = AnsibleModule(
9587
argument_spec=dict(
9688
ec2_url=dict(),
9789
region=dict(aliases=['aws_region', 'ec2_region'],
@@ -108,35 +100,34 @@ def main():
108100
region = module.params.get('region')
109101
ec2_url = module.params.get('ec2_url')
110102

111-
# If we have a region specified, connect to its endpoint.
103+
# If region is specified, create a session with boto3 and connect to the EC2 service
112104
if region:
113105
try:
114-
ec2 = connect_to_region(region, aws_access_key_id=aws_access_key,
115-
aws_secret_access_key=aws_secret_key)
116-
except boto.exception.NoAuthHandlerFound as e:
117-
module.fail_json(msg=str(e))
118-
# If we specified an ec2_url then try connecting to it
119-
elif ec2_url:
120-
try:
121-
ec2 = boto.connect_ec2_endpoint(ec2_url, aws_access_key,
122-
aws_secret_key)
123-
except boto.exception.NoAuthHandlerFound as e:
124-
module.fail_json(msg=str(e))
106+
ec2 = boto3.resource('ec2', region_name=region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key)
107+
except Exception as e:
108+
module.fail_json(msg=f"Error connecting to AWS EC2: {str(e)}")
125109
else:
126-
module.fail_json(msg="Either region or ec2_url must be specified")
110+
module.fail_json(msg="Region must be specified")
111+
112+
# If EC2 URL is provided, it can be used for connection
113+
if ec2_url:
114+
module.fail_json(msg="ec2_url is not supported in boto3 connection. Please use region instead.")
127115

128116
instances = []
129117
instance_ids = []
130-
for res in ec2.get_all_instances(filters={'tag:' + tag: value
131-
for tag, value in six.iteritems(module.params.get('tags'))}):
132-
for inst in res.instances:
133-
if inst.state == "running":
134-
instances.append({k: v for k, v in six.iteritems(inst.__dict__)
135-
if isinstance(v, (six.string_types))})
136-
instance_ids.append(inst.id)
137-
module.exit_json(changed=False, instances=instances,
138-
instance_ids=instance_ids)
139118

119+
# Get all instances with the specified tags
120+
filters = {'tag:' + tag: value for tag, value in module.params.get('tags', {}).items()}
121+
try:
122+
instances_query = ec2.instances.filter(Filters=[{'Name': f'tag:{tag}', 'Values': [value]} for tag, value in filters.items()])
123+
for instance in instances_query:
124+
if instance.state['Name'] == 'running':
125+
instances.append({k: v for k, v in instance.__dict__.items() if isinstance(v, str)})
126+
instance_ids.append(instance.id)
127+
except Exception as e:
128+
module.fail_json(msg=f"Error querying EC2 instances: {str(e)}")
129+
130+
module.exit_json(changed=False, instances=instances, instance_ids=instance_ids)
140131

141132
# this is magic, see lib/ansible/module_common.py
142133
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>

playbooks/roles/common/tasks/main.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
- name: Check Configuration Sources
33
fail:
44
msg: "Configuration Sources Checking (COMMON_EXTRA_CONFIGURATION_SOURCES_CHECKING) is enabled, you must define {{ item }}"
5-
when: COMMON_EXTRA_CONFIGURATION_SOURCES_CHECKING and ({{ item }} is not defined or {{ item }} != True)
5+
when:
6+
- COMMON_EXTRA_CONFIGURATION_SOURCES_CHECKING
7+
- item not in vars or vars[item] != True
68
with_items: "{{ COMMON_EXTRA_CONFIGURATION_SOURCES }}"
79
tags:
810
- "install"
@@ -170,8 +172,15 @@
170172
state: present
171173
extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }}"
172174
executable: pip3
173-
when: ansible_distribution in common_debian_variants
175+
when: ansible_distribution in common_debian_variants and ansible_distribution_release != "noble"
174176

177+
- name: pip install virtualenv
178+
pip:
179+
name: "{{ common_pip_pkgs }}"
180+
state: present
181+
extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }} --break-system-packages"
182+
executable: pip3
183+
when: ansible_distribution in common_debian_variants and ansible_distribution_release == "noble"
175184

176185
- name: update /etc/hosts
177186
template:

playbooks/roles/launch_ec2/tasks/main.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,27 @@
3535
when: terminate_instance == true and elb and tag_lookup.instance_ids|length == 1
3636

3737
- name: Launch ec2 instance
38-
local_action:
39-
module: ec2
40-
keypair: "{{ keypair }}"
41-
group: "{{ security_group }}"
38+
community.aws.ec2_instance:
39+
key_name: "{{ keypair }}"
40+
security_groups:
41+
- "{{ security_group }}"
4242
instance_type: "{{ instance_type }}"
4343
instance_initiated_shutdown_behavior: "{{ instance_initiated_shutdown_behavior }}"
44-
image: "{{ ami }}"
44+
image_id: "{{ ami }}"
4545
vpc_subnet_id: "{{ vpc_subnet_id }}"
46-
assign_public_ip: yes
4746
wait: true
4847
region: "{{ region }}"
49-
instance_tags: "{{ instance_tags }}"
48+
tags: "{{ instance_tags }}"
49+
network:
50+
assign_public_ip: true
5051
volumes:
5152
- device_name: /dev/sda1
52-
volume_size: "{{ root_ebs_size }}"
53-
delete_on_termination: true
54-
volume_type: "gp2"
55-
encrypted: true
56-
zone: "{{ zone }}"
57-
instance_profile_name: "{{ instance_profile_name }}"
53+
ebs:
54+
volume_size: "{{ root_ebs_size }}"
55+
delete_on_termination: true
56+
volume_type: "gp2"
57+
encrypted: true
58+
instance_role: "{{ instance_profile_name }}"
5859
user_data: "{{ user_data }}"
5960
register: ec2
6061

@@ -97,7 +98,7 @@
9798
- name: Add new instance to host group
9899
local_action:
99100
module: add_host
100-
hostname: "{{ item.public_ip }}"
101+
hostname: "{{ item.network_interfaces[0].association.public_ip }}"
101102
groups: launched
102103
with_items: "{{ ec2.instances }}"
103104

playbooks/roles/mongo_7_0/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mongo_journal_dir: "{{ COMMON_DATA_DIR }}/mongo/mongodb/journal"
1717
mongo_user: mongodb
1818

1919
MONGODB_REPO: "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/{{ MONGO_VERSION_MAJOR_MINOR }} multiverse"
20+
MONGODB_REPO_NOBLE: "deb http://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/{{ MONGO_VERSION_MAJOR_MINOR }} multiverse"
2021

2122
mongodb_debian_pkgs:
2223
- "mongodb-org={{ MONGO_VERSION }}"

playbooks/roles/mongo_7_0/tasks/main.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
state: present
2828
version: "{{ PYMONGO_VERSION }}"
2929
extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }}"
30+
when: ansible_distribution_release != "noble"
31+
tags:
32+
- "install"
33+
- "install:app-requirements"
34+
35+
- name: install python pymongo for mongo_user ansible module
36+
pip:
37+
name: pymongo
38+
state: present
39+
version: "{{ PYMONGO_VERSION }}"
40+
extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }} --break-system-packages"
41+
when: ansible_distribution_release == "noble"
3042
tags:
3143
- "install"
3244
- "install:app-requirements"
@@ -46,6 +58,17 @@
4658
apt_repository:
4759
repo: "{{ MONGODB_REPO }}"
4860
state: present
61+
when: ansible_distribution_release != "noble"
62+
tags:
63+
- "install"
64+
- "install:app-requirements"
65+
- "mongo_packages"
66+
67+
- name: add the mongodb repo to the sources list
68+
apt_repository:
69+
repo: "{{ MONGODB_REPO_NOBLE }}"
70+
state: present
71+
when: ansible_distribution_release == "noble"
4972
tags:
5073
- "install"
5174
- "install:app-requirements"
@@ -172,7 +195,9 @@
172195
- name: determine if backup tasks should run
173196
set_fact:
174197
is_backup_node: true
175-
when: MONGO_BACKUP_ENABLED and '{{ ansible_default_ipv4.address|default(ansible_all_ipv4_addresses[0]) }}' == '{{ MONGO_BACKUP_NODE }}'
198+
when:
199+
- MONGO_BACKUP_ENABLED
200+
- ansible_default_ipv4.address | default(ansible_all_ipv4_addresses[0]) == MONGO_BACKUP_NODE
176201
tags:
177202
- "backup:mongo"
178203

playbooks/roles/mysql/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ remove_experimental_mysql: false
44
mysql_debian_pkgs_default:
55
- python3-mysqldb
66
mysql_release_specific_debian_pkgs:
7-
xenial:
8-
- python-mysqldb
97
bionic:
108
- python-mysqldb
119
focal:
1210
- python3-mysqldb
11+
noble:
12+
- python3-mysqldb
1313
mysql_debian_pkgs: "{{ mysql_debian_pkgs_default + mysql_release_specific_debian_pkgs[ansible_distribution_release] }}"
1414

1515
mysql_server_pkg: "{{ 'mysql-server-5.7' if mysql_server_version_5_7 is defined and (mysql_server_version_5_7 | bool) else 'mysql-server-5.6' }}"

playbooks/roles/mysql/tasks/mysql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
name: "{{ mysql_server_pkg }}"
4545
install_recommends: yes
4646
state: present
47-
when: ansible_distribution_release != 'focal'
47+
when: ansible_distribution_release != 'focal' and ansible_distribution_release != 'noble'
4848

4949
- name: Set default character sets and collations
5050
template:
@@ -53,7 +53,7 @@
5353
owner: root
5454
group: root
5555
mode: 0644
56-
when: ansible_distribution_release != 'bionic' and ansible_distribution_release != 'focal'
56+
when: ansible_distribution_release != 'bionic' and ansible_distribution_release != 'focal' and ansible_distribution_release != 'noble'
5757

5858
- name: add the mysql signing key
5959
apt_key:
@@ -95,7 +95,7 @@
9595
name: "{{ mysql_server_8_0_pkgs }}"
9696
state: present
9797
update_cache: yes
98-
when: ansible_distribution_release == 'focal' and mysql_8_0_install
98+
when: ((ansible_distribution_release == 'focal') or (ansible_distribution_release == 'noble')) and mysql_8_0_install
9999

100100

101101
- name: restart mysql

playbooks/roles/redis/defaults/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ redis_group: redis
2828
#
2929

3030
REDIS_REPO: "deb https://packages.redis.io/deb {{ ansible_distribution_release }} main"
31-
REDIS_VERSION: "6:7.2.0-1rl1~focal1"
31+
redis_release_specific_pkg:
32+
focal: "6:7.2.0-1rl1~focal1"
33+
noble: "6:7.4.2-1rl1~noble1"
3234

3335
redis_debian_pkgs:
34-
- "redis-tools={{ REDIS_VERSION }}"
35-
- "redis-server={{ REDIS_VERSION }}"
36+
- "redis-tools={{ redis_release_specific_pkg[ansible_distribution_release] }}"
37+
- "redis-server={{ redis_release_specific_pkg[ansible_distribution_release] }}"
3638

3739
redis_redhat_pkgs: []

0 commit comments

Comments
 (0)