Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit 4187ddc

Browse files
author
Riaan Nolan
committed
Merge branch 'feature/update-packer' into 'master'
disable packer builds for now, testing docker provider with ansible See merge request all-staff/hashiqube!168
1 parent 6d608b5 commit 4187ddc

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

ansible/requirements.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ requests==2.25.1
5050
requests-ntlm==1.1.0
5151
resolvelib==0.5.4
5252
rich==10.4.0
53-
ruamel.yaml==0.17.10
54-
ruamel.yaml.clib==0.2.4
53+
ruamel.yaml
54+
ruamel.yaml.clib
5555
selinux==0.2.1
56-
setuptools==51.1.1
56+
setuptools
5757
six==1.16.0
5858
subprocess-tee==0.3.2
5959
tenacity==7.0.0
6060
text-unidecode==1.3
6161
urllib3==1.26.6
6262
wcmatch==8.2
6363
websocket-client==1.1.0
64-
wheel==0.36.2
64+
wheel
6565
xmltodict==0.12.0
6666
yamllint
6767
ansible-tower-cli

hashicorp/packer.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ EOF
9595
vault kv put kv/ansible devops="all the things"
9696
ANSIBLE_TOKEN=$(vault write auth/approle/login role_id="${ANSIBLE_ROLE_ID}" secret_id="${ANSIBLE_ROLE_SECRET_ID}" | grep token | head -n1 | tr -s ' ' | cut -d ' ' -f2)
9797
echo -e '\e[38;5;198m'"++++ ANSIBLE_TOKEN: ${ANSIBLE_TOKEN}"
98-
sed -i "s:token=[^ ]*:token=${ANSIBLE_TOKEN}:" /vagrant/hashicorp/packer/linux/ubuntu/playbook.yml
98+
# sed -i "s:token=[^ ]*:token=${ANSIBLE_TOKEN}:" /vagrant/hashicorp/packer/linux/ubuntu/playbook.yml
9999
echo -e '\e[38;5;198m'"++++ Install Ansible to configure Containers/VMs/AMIs/Whatever"
100100
sudo DEBIAN_FRONTEND=noninteractive apt-get update
101101
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip
@@ -115,7 +115,9 @@ EOF
115115
sudo bash /vagrant/docker/docker.sh
116116
fi
117117
echo -e '\e[38;5;198m'"++++ Packer build Linux Docker container configured with Ansible"
118-
packer build /vagrant/hashicorp/packer/linux/ubuntu/ubuntu20.04.json
118+
# packer build /vagrant/hashicorp/packer/linux/ubuntu/ubuntu-2204.hcl
119+
cd /vagrant/hashicorp/packer/
120+
./run.sh
119121
}
120122

121123
packer-install

hashicorp/packer/linux/ubuntu/ubuntu-1804.pkr.hcl

+8-2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ source "vagrant" "ubuntu-1804" {
7878
output_dir = "${var.build_directory}/ubuntu-1804/vagrant"
7979
}
8080

81+
source "docker" "ubuntu-1804" {
82+
image = "ubuntu:18.04"
83+
commit = false
84+
discard = true
85+
}
86+
8187
# a build block invokes sources and runs provisioning steps on them. The
8288
# documentation for build blocks can be found here:
8389
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
8490
build {
85-
sources = ["source.vagrant.ubuntu-1804", "source.azure-arm.ubuntu-1804", "source.amazon-ebs.ubuntu-1804", "source.googlecompute.ubuntu-1804"]
91+
sources = ["source.docker.ubuntu-1804", "source.vagrant.ubuntu-1804", "source.azure-arm.ubuntu-1804", "source.amazon-ebs.ubuntu-1804", "source.googlecompute.ubuntu-1804"]
8692

8793
provisioner "shell" {
8894
inline = [
@@ -94,7 +100,7 @@ build {
94100
command = "./scripts/ansible.sh"
95101
extra_arguments = [
96102
#"-v",
97-
"--extra-vars", "ansible_become=true version_number=${local.version_number}"
103+
"--extra-vars", "ansible_python_interpreter=/usr/bin/python3 ansible_become=true version_number=${local.version_number}"
98104
]
99105
ansible_ssh_extra_args = [
100106
"-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"

hashicorp/packer/linux/ubuntu/ubuntu-2004.pkr.hcl

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ source "vagrant" "ubuntu-2004" {
7878
output_dir = "${var.build_directory}/ubuntu-2004/vagrant"
7979
}
8080

81+
source "docker" "ubuntu-2004" {
82+
image = "ubuntu:20.04"
83+
commit = false
84+
discard = true
85+
}
86+
8187
# a build block invokes sources and runs provisioning steps on them. The
8288
# documentation for build blocks can be found here:
8389
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
8490
build {
85-
sources = ["source.vagrant.ubuntu-2004", "source.azure-arm.ubuntu-2004", "source.amazon-ebs.ubuntu-2004", "source.googlecompute.ubuntu-2004"]
91+
sources = ["source.docker.ubuntu-2004", "source.vagrant.ubuntu-2004", "source.azure-arm.ubuntu-2004", "source.amazon-ebs.ubuntu-2004", "source.googlecompute.ubuntu-2004"]
8692

8793
provisioner "shell" {
8894
inline = ["cat /etc/os-release"]

hashicorp/packer/linux/ubuntu/ubuntu-2204.pkr.hcl

+11-5
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ source "vagrant" "ubuntu-2204" {
7878
output_dir = "${var.build_directory}/ubuntu-2204/vagrant"
7979
}
8080

81+
source "docker" "ubuntu-2204" {
82+
image = "ubuntu:22.04"
83+
commit = false
84+
discard = true
85+
}
86+
8187
# a build block invokes sources and runs provisioning steps on them. The
8288
# documentation for build blocks can be found here:
8389
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
8490
build {
85-
sources = ["source.vagrant.ubuntu-2204", "source.azure-arm.ubuntu-2204", "source.amazon-ebs.ubuntu-2204", "source.googlecompute.ubuntu-2204"]
91+
sources = ["source.docker.ubuntu-2204", "source.vagrant.ubuntu-2204", "source.azure-arm.ubuntu-2204", "source.amazon-ebs.ubuntu-2204", "source.googlecompute.ubuntu-2204"]
8692

8793
provisioner "shell" {
8894
inline = ["cat /etc/os-release"]
@@ -92,9 +98,9 @@ build {
9298
command = "./scripts/ansible.sh"
9399
user = "${build.User}"
94100
extra_arguments = [
95-
#"-v",
101+
"-vvv",
96102
"--tags", "always,day0",
97-
"--extra-vars", "ansible_become=true version_number=${local.version_number}"
103+
"--extra-vars", "ansible_python_interpreter=/vagrant/ansible/ansible-venv/bin/python ansible_become=true version_number=${local.version_number}"
98104
]
99105
ansible_ssh_extra_args = [
100106
"-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
@@ -108,7 +114,7 @@ build {
108114
user = "${build.User}"
109115
extra_arguments = [
110116
#"-v",
111-
"--extra-vars", "foo=bar"
117+
"--extra-vars", "ansible_python_interpreter=/vagrant/ansible/ansible-venv/bin/python foo=bar"
112118
]
113119
ansible_ssh_extra_args = [
114120
"-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
@@ -123,7 +129,7 @@ build {
123129
user = "${build.User}"
124130
extra_arguments = [
125131
#"-v",
126-
"--extra-vars", "foo=bar"
132+
"--extra-vars", "ansible_python_interpreter=/vagrant/ansible/ansible-venv/bin/python foo=bar"
127133
]
128134
ansible_ssh_extra_args = [
129135
"-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"

hashicorp/packer/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ scripts/install-ansible.sh
1818
echo -e "++++ "
1919
echo -e "++++ Run Packer"
2020
echo -e "++++ "
21-
packer build -force -only='vagrant.ubuntu-2204' all
21+
# packer build -force -only='docker.ubuntu-2204' all

hashicorp/packer/scripts/install-ansible.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ python3 -V
2424
pip3 -V
2525

2626
echo -e "++++ "
27-
echo -e "++++ Install Python Pip Packages"
27+
echo -e "++++ Install Python Pip Packages (Will take ~5 minutes)"
2828
echo -e "++++ "
2929
pip3 install -r ../../ansible/requirements.txt --no-cache-dir --quiet
3030

hashiqube/basetools.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export DEBIAN_FRONTEND=noninteractive
44
export PATH=$PATH:/root/.local/bin
55
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes update -o Acquire::CompressionTypes::Order::=gz
66
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes upgrade
7-
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install swapspace rkhunter jq curl unzip software-properties-common bzip2 git make python3.9 python3-pip python3-dev python3-virtualenv golang-go apt-utils ntp update-motd toilet figlet nano iputils-ping dnsutils iptables telnet
7+
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install swapspace rkhunter jq curl unzip software-properties-common bzip2 git make python3.9 python3-pip python3-dev python3-venv python3-virtualenv golang-go apt-utils ntp update-motd toilet figlet nano iputils-ping dnsutils iptables telnet
88
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 --force
99
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 --force
1010
python -V

0 commit comments

Comments
 (0)