Skip to content

Commit 99e42b7

Browse files
committed
Merge branch 'v3' into PMM-12641-clean-up-build-scripts
2 parents 9b0e96b + 3f66a30 commit 99e42b7

File tree

17 files changed

+782
-16
lines changed

17 files changed

+782
-16
lines changed

build/Makefile

+6-16
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ fetch:
99
-o ${PACKER_CACHE_DIR}/id_rsa_vagrant
1010
chmod 600 ${PACKER_CACHE_DIR}/id_rsa_vagrant
1111
test -f ${PACKER_CACHE_DIR}/box/oracle9.ova \
12-
|| curl https://vagrantcloud.com/bento/boxes/oracle-9.0/versions/202207.20.0/providers/virtualbox.box -o ${PACKER_CACHE_DIR}/box/oracle9.ova
12+
|| curl -fL https://vagrantcloud.com/bento/boxes/oracle-9.0/versions/202207.20.0/providers/virtualbox.box -o ${PACKER_CACHE_DIR}/box/oracle9.ova
1313

1414
# NOTE: image from vagrant registry is twice as large
1515
test -f ${PACKER_CACHE_DIR}/box/box.ovf \
1616
|| tar -C ${PACKER_CACHE_DIR}/box -xvf ${PACKER_CACHE_DIR}/box/oracle9.ova
1717

1818
deps:
1919
mkdir -p ${PACKER_CACHE_DIR} ~/bin || :
20-
curl https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip -o ${PACKER_CACHE_DIR}/packer.zip
20+
curl -fL https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip -o ${PACKER_CACHE_DIR}/packer.zip
2121
unzip -o ${PACKER_CACHE_DIR}/packer.zip -d ~/bin
2222

2323
pmm-ovf: fetch
2424
/usr/bin/packer build \
25-
-only virtualbox-ovf -color=false packer/pmm.el9.json \
26-
| tee build.log
25+
-only virtualbox-ovf -color=false packer/pmm.el9.json | tee build.log
2726

2827
# NOTE: no difference between rc and dev-latest (i.e. pmm-ovf) ATM
2928
pmm-ovf-rc: fetch
3029
/usr/bin/packer build \
31-
-only virtualbox-ovf -color=false packer/pmm.el9.json \
32-
| tee build.log
30+
-only virtualbox-ovf -color=false packer/pmm.el9.json | tee build.log
3331

3432
pmm-digitalocean:
3533
packer build -only digitalocean -var 'single_disk=true' packer/pmm.json
@@ -38,16 +36,8 @@ pmm-azure:
3836
packer build -only azure-arm packer/pmm.json
3937

4038
pmm-ami:
41-
mkdir -p update && \
42-
docker run --rm -v ${HOME}/.aws:/root/.aws -v `pwd`:/build -w /build hashicorp/packer:${PACKER_VERSION} \
43-
build -only amazon-ebs -color=false packer/pmm.el9.json
44-
45-
# NOTE: no difference between rc and dev-latest (pmm-ami) for now, TBD
46-
pmm-ami-rc:
47-
mkdir -p update && \
48-
docker run --rm -v ${HOME}/.aws:/root/.aws -v `pwd`:/build -w /build hashicorp/packer:${PACKER_VERSION} \
49-
build -only amazon-ebs '-color=false' packer/pmm.el9.json
50-
39+
docker run --rm -v ${HOME}/.aws:/root/.aws -v `pwd`:/build -w /build \hashicorp/packer:${PACKER_VERSION} \
40+
build -only amazon-ebs -color=false packer/pmm.json | tee build.log
5141
## ----------------- PACKER ------------------
5242

5343
check: ## Run required checks and linters

build/packer/ansible/pmm.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Create PMM image
3+
hosts: all
4+
become: yes
5+
become_user: root
6+
roles:
7+
- cloud-node
8+
- lvm-init
9+
- podman-setup
10+
- ami-ovf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
5+
PATH=/bin:/sbin
6+
7+
SOURCE=$(
8+
cat /var/lib/cloud/data/status.json 2>/dev/null \
9+
| python -c 'import json, sys; print json.load(sys.stdin)["v1"]["datasource"];' 2>/dev/null
10+
)
11+
12+
IP=$(ip route get 1 2>/dev/null | awk '{print $7;exit}')
13+
if [ "x$SOURCE" = "xDataSourceEc2" ]; then
14+
IP=$(curl --connect-timeout 5 -s http://169.254.169.254/latest/meta-data/public-ipv4)
15+
fi
16+
17+
if [ -z "$IP" ]; then
18+
IP=$(ip addr show up | grep 'inet ' | awk '{print$2}' | cut -d '/' -f 1 | grep -v '^127.')
19+
fi
20+
21+
echo "
22+
23+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24+
25+
Percona Monitoring and Management https://${IP}/
26+
27+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28+
" | tee -a /dev/tty0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: PMM | Delete ec2-user EL9
3+
shell: cd /tmp; nohup sh -c "trap 'userdel -r ec2-user' EXIT; sleep 600" </dev/null >/dev/null 2>&1 &
4+
when:
5+
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
6+
- ansible_distribution_major_version == '9'
7+
8+
- name: PMM | Delete vagrant
9+
shell: cd /tmp; nohup sh -c "trap 'userdel -r vagrant' EXIT; sleep 600" </dev/null >/dev/null 2>&1 &
10+
11+
- name: PMM | Delete Azure user
12+
shell: cd /tmp; nohup sh -c "trap '/usr/sbin/waagent -force -deprovision+user && sync' EXIT; sleep 600" </dev/null >/dev/null 2>&1 &
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=URL banner service
3+
Wants=network-online.target
4+
After=network-online.target
5+
6+
[Service]
7+
ExecStart=/opt/show-url
8+
9+
[Install]
10+
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
PATH=/bin:/sbin
4+
SOURCE=
5+
6+
if [ -f /var/lib/cloud/data/status.json ]; then
7+
SOURCE=$(
8+
cat /var/lib/cloud/data/status.json 2>/dev/null \
9+
| python -c 'import json, sys; print json.load(sys.stdin)["v1"]["datasource"];' 2>/dev/null
10+
)
11+
fi
12+
13+
IP=$(ip route get 1 2>/dev/null | awk '{print $7;exit}')
14+
if [ "x$SOURCE" = "xDataSourceEc2" ]; then
15+
IP=$(curl --connect-timeout 5 -s http://169.254.169.254/latest/meta-data/public-ipv4)
16+
fi
17+
18+
if [ -z "$IP" ]; then
19+
IP=$(ip addr show up | grep 'inet ' | awk '{print$2}' | cut -d '/' -f 1 | grep -v '^127.')
20+
fi
21+
22+
echo "
23+
24+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25+
26+
Percona Monitoring and Management https://${IP}/
27+
28+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29+
" | tee -a /dev/tty0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# Common things for all AWS images
3+
4+
- name: ami | Enable swap on AWS
5+
when: ansible_virtualization_type == "xen"
6+
command: dd if=/dev/zero of=/var/tmp/swapfile bs=1024 count=1000000
7+
8+
- name: ami | Enable swap on AWS
9+
when: ansible_virtualization_type == "xen"
10+
file:
11+
path: /var/tmp/swapfile
12+
owner: root
13+
group: root
14+
mode: 0600
15+
16+
- name: ami | Enable swap on AWS
17+
when: ansible_virtualization_type == "xen"
18+
command: mkswap /var/tmp/swapfile
19+
20+
- name: ami | Enable swap on AWS
21+
when: ansible_virtualization_type == "xen"
22+
mount:
23+
path: swap
24+
src: /var/tmp/swapfile
25+
fstype: swap
26+
opts: defaults
27+
state: present
28+
29+
- name: ami | Enable swap on AWS
30+
when: ansible_virtualization_type == "xen"
31+
command: swapon -a
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
---
2+
# Common things for all cloud images
3+
- name: Packages | Add EPEL repository for EL9
4+
when:
5+
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
6+
- ansible_distribution_major_version == '9'
7+
yum:
8+
name: epel-release
9+
state: installed
10+
11+
- name: Packages | Install OS tools for EL9
12+
when:
13+
- (ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux') and ansible_distribution_major_version == '9'
14+
yum:
15+
name:
16+
- screen
17+
- yum-utils
18+
- cloud-init
19+
- firewalld
20+
- python3-libselinux
21+
- python3-firewall
22+
23+
- name: Firewalld | Start EL9
24+
when:
25+
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
26+
- ansible_distribution_major_version == '9'
27+
- ansible_os_family == 'RedHat'
28+
service:
29+
name: firewalld
30+
state: started
31+
enabled: yes
32+
33+
- name: Add firewalld rule | EL9
34+
when:
35+
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
36+
- ansible_distribution_major_version == '9'
37+
firewalld: port={{ item }} permanent=true state=enabled immediate=yes
38+
with_items:
39+
- 80/tcp
40+
- 443/tcp
41+
42+
- name: cleanup cache | Cleanup cache
43+
file: path={{ item }} state=absent
44+
with_items:
45+
- /var/lib/cloud/sem
46+
- /var/lib/cloud/data
47+
- /var/lib/cloud/instance
48+
- /var/lib/cloud/instances
49+
- /var/log/cloud-init.log
50+
- /var/log/cloud-init-output.log
51+
52+
- name: create dir | Create getty@.service.d directory
53+
file:
54+
path: /etc/systemd/system/getty@.service.d
55+
state: directory
56+
57+
- name: cloud-init | Disable console cleanup
58+
copy:
59+
content: |
60+
[Service]
61+
TTYVTDisallocate=no
62+
dest: /etc/systemd/system/getty@.service.d/nodisallocate.conf
63+
mode: 0644
64+
65+
- name: root password | Set root password
66+
when: ansible_virtualization_type == "virtualbox"
67+
user:
68+
name: root
69+
password: "$6$J7pGg2a7vuRTbTV5$vORqkiAKdkyomU3iYwr/SPn.yLIkGsl5ludEx5DUvGVASSTquTjOldHt/nUWrFRnJeZyzt6CIOjAcugbcfGtN1"
70+
71+
- name: root password | Set root password
72+
when: ansible_virtualization_type == "virtualbox"
73+
command: chage -d 0 root
74+
changed_when: False
75+
76+
- name: root password | Disable root password
77+
when: ansible_virtualization_type != "virtualbox"
78+
command: passwd --delete root
79+
changed_when: False
80+
81+
- name: root password | Disable root password
82+
when: ansible_virtualization_type != "virtualbox"
83+
command: passwd --lock root
84+
changed_when: False
85+
86+
- name: chronyd | Fix start-up sequence
87+
replace:
88+
dest: /usr/lib/systemd/system/chronyd.service
89+
regexp: "After="
90+
replace: 'Before=cloud-config.target\nAfter=network-online.target '
91+
92+
- name: disable root user | Disable root user
93+
copy:
94+
content: |
95+
no_ssh_fingerprints: true
96+
disable_root: true
97+
dest: /etc/cloud/cloud.cfg.d/00_disable-root.cfg
98+
mode: 0644
99+
100+
- name: add user | Add admin user
101+
when: create_admin == "true"
102+
user:
103+
name: admin
104+
comment: Cloud User
105+
groups: wheel,adm,systemd-journal
106+
shell: /bin/bash
107+
108+
- name: add user | Add sudo for admin user
109+
when: create_admin == "true"
110+
copy:
111+
content: |
112+
admin ALL=(ALL) NOPASSWD: ALL
113+
dest: /etc/sudoers.d/90-admin-user
114+
mode: 0440
115+
116+
- name: change cloud user for OVF EL9 | Change cloud user
117+
when:
118+
- create_admin == "true"
119+
- ansible_virtualization_type == "virtualbox"
120+
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
121+
- ansible_distribution_major_version == '9'
122+
replace:
123+
dest: /etc/cloud/cloud.cfg
124+
regexp: "name: cloud-user"
125+
replace: "name: admin"
126+
127+
- name: change cloud user for AMI EL9 | Change cloud user
128+
when:
129+
- create_admin == "true"
130+
- ansible_virtualization_type != "virtualbox"
131+
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
132+
- ansible_distribution_major_version == '9'
133+
replace:
134+
dest: /etc/cloud/cloud.cfg.d/00_ol-default-user.cfg
135+
regexp: "name: ec2-user"
136+
replace: "name: admin"
137+
138+
- name: cloud-init configuration | stat /etc/waagent.conf
139+
stat: path=/etc/waagent.conf
140+
register: waagent_conf
141+
142+
- name: cloud-init configuration | Enable cloud-init for Azure
143+
when: waagent_conf.stat.exists
144+
replace:
145+
dest: /etc/waagent.conf
146+
regexp: "Provisioning.UseCloudInit=n"
147+
replace: "Provisioning.UseCloudInit=y"
148+
149+
- name: Azure tweaks
150+
when: waagent_conf.stat.exists
151+
replace:
152+
dest: /usr/lib/python2.7/site-packages/azurelinuxagent/pa/deprovision/default.py
153+
regexp: "warnings, actions, deluser=deluser"
154+
replace: "warnings, actions, include_once=False, deluser=deluser"
155+
156+
- name: PMM URL file | Add script which show PMM URL
157+
copy:
158+
src: show-url
159+
dest: /opt/show-url
160+
mode: 0755
161+
162+
- name: PMM URL Service | Add Service for script which show PMM URL
163+
copy:
164+
src: banner.service
165+
dest: /etc/systemd/system/banner.service
166+
mode: 0755
167+
168+
- name: Enable PMM URL Service | Enable PMM URL Service
169+
systemd:
170+
name: banner
171+
state: started
172+
enabled: yes
173+
174+
- name: PMM IP in Log | Add PMM IP in Log file
175+
lineinfile:
176+
line: 'IP: \4'
177+
path: /etc/issue
178+
create: yes
179+
180+
- import_tasks: security.yml
181+
- import_tasks: ovf.yml
182+
- import_tasks: ami.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# Common things for all OVF images
3+
- name: ovf | Disable EC2, CloudStack
4+
when: ansible_virtualization_type == "virtualbox"
5+
copy:
6+
content: |
7+
datasource_list: [ NoCloud, ConfigDrive, OpenNebula, DigitalOcean, Azure, AltCloud, OVF, MAAS, GCE, OpenStack, CloudSigma, SmartOS, None ]
8+
disable_ec2_metadata: true
9+
datasource:
10+
OpenStack:
11+
max_wait: 6
12+
timeout: 3
13+
retries: 2
14+
dest: /etc/cloud/cloud.cfg.d/90_disable-cloud.cfg
15+
mode: 0644
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: security | Disable root SSH access
3+
lineinfile:
4+
dest: /etc/ssh/sshd_config
5+
regexp: '^PermitRootLogin'
6+
line: 'PermitRootLogin no'
7+
state: present
8+
9+
- name: security | Remove authorized_keys file
10+
file:
11+
path: /root/.ssh/authorized_keys
12+
state: absent

0 commit comments

Comments
 (0)