|
1 | 1 | #!/usr/bin/env bash
|
2 |
| -set -ex |
| 2 | +set -e |
3 | 3 |
|
4 | 4 | if [[ $# -ne 2 ]]; then
|
5 |
| - echo "Usage: $0 <gateway_name> <gcp_project>" |
6 |
| - exit 1 |
| 5 | + echo "Usage: $0 <gateway_name> <gcp_project>" |
| 6 | + exit 1 |
7 | 7 | fi
|
8 | 8 |
|
9 |
| -if [[ ! -f "/root/sa.json" ]]; then |
10 |
| - echo "You need to place appropriate sa json at /root/sa.json before running this script." |
11 |
| -fi |
12 |
| - |
13 |
| -mkdir -p /var/log/naisdevice |
14 |
| -chmod 755 /var/log/naisdevice |
15 |
| - |
16 | 9 | name="$1"
|
17 | 10 | project="$2"
|
18 |
| -proxy="" |
19 | 11 | proxy_yaml=""
|
20 | 12 | role="gateways"
|
| 13 | +# onprem settings |
21 | 14 | if [[ $(hostname) =~ a30drvl ]]; then
|
22 |
| - # onprem settings |
23 |
| - role="onprem_gateways" |
24 |
| - proxy="http://webproxy-internett.nav.no:8088" |
25 |
| - proxy_yaml="proxy_env: |
26 |
| - https_proxy: $proxy" |
| 15 | + if [[ ! -f "/root/sa.json" ]]; then |
| 16 | + echo "You need to place appropriate sa json at /root/sa.json before running this script." |
| 17 | + exit 1 |
| 18 | + fi |
| 19 | + |
| 20 | + role="onprem_gateways" |
| 21 | + proxy_yaml="proxy_env: |
| 22 | + https_proxy: http://webproxy-internett.nav.no:8088" |
| 23 | + export HTTPS_PROXY="http://webproxy-internett.nav.no:8088" |
27 | 24 | fi
|
28 | 25 |
|
29 |
| -# Install Ansible |
| 26 | +apt-get install --yes ca-certificates curl apt-transport-https gnupg |
| 27 | + |
| 28 | +curl -L https://europe-north1-apt.pkg.dev/doc/repo-signing-key.gpg | gpg --dearmor >/etc/apt/trusted.gpg.d/nais-ppa-google-artifact-registry.gpg |
| 29 | +echo 'deb [arch=amd64] https://europe-north1-apt.pkg.dev/projects/naisdevice controlplane main' >/etc/apt/sources.list.d/europe_north1_apt_pkg_dev_projects_naisdevice.list |
| 30 | + |
30 | 31 | apt update --yes
|
31 |
| -apt install ansible --yes |
| 32 | +apt install ansible gateway-agent --yes |
32 | 33 |
|
33 |
| -# Configure ansible inventory |
34 |
| -cat <<EOF > /root/ansible-inventory.yaml |
| 34 | +cat <<EOF >/root/ansible-inventory.yaml |
35 | 35 | all:
|
36 | 36 | vars:
|
37 | 37 | name: $name
|
|
43 | 43 | $(hostname):
|
44 | 44 | EOF
|
45 | 45 |
|
46 |
| -# Set up cron for Ansible |
47 |
| -if ! crontab -l 2>/dev/null | grep "ansible-pull"; then |
48 |
| - ( crontab -l 2>/dev/null; echo "*/5 * * * * [ \$(pgrep ansible-pull -c) -eq 0 ] && HTTPS_PROXY=$proxy /usr/bin/ansible-pull --only-if-changed -U https://github.com/nais/device ansible/site.yml -i /root/ansible-inventory.yaml >> /var/log/naisdevice/ansible.log") | crontab - |
49 |
| -fi |
50 |
| - |
| 46 | +echo "add the following line to crontab:" |
| 47 | +echo "*/5 * * * * [ \$(pgrep ansible-pull -c) -eq 0 ] && HTTPS_PROXY=$HTTPS_PROXY /usr/bin/ansible-pull --only-if-changed -U https://github.com/nais/device ansible/site.yml -i /root/ansible-inventory.yaml >> /var/log/naisdevice/ansible.log" |
0 commit comments