File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ [defaults]
2
+ inventory = ./ansible_nb_inv.yaml
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ set -xeuo pipefail
4
+
5
+ dnf -y install ansible
6
+
7
+ cd /root
8
+
9
+ cat << 'EOF ' > ansible.cfg
10
+ ${ansible_cfg}
11
+ EOF
12
+
13
+ cat << 'EOF ' > ansible_nb_inv.yaml
14
+ ${ansible_nb_inv_yaml}
15
+ EOF
16
+
17
+ NETBOX_API=https://${netbox_api} /
18
+
19
+ echo " export NETBOX_API=$$ {NETBOX_API}" >> .bash_profile
20
+
21
+ until [ " $( curl -o /dev/null -sk --max-time 2 -w ' %%{http_code}' " $$ {NETBOX_API}" ) " -eq 200 ]; do
22
+ sleep 30
23
+ done
24
+
25
+ TOKEN=$( curl " $$ {NETBOX_API}/api/users/tokens/provision/" -H ' Content-Type: application/json' -d ' {"username": "admin", "password": "${admin_password}"}' -sk | jq ' .key' -r)
26
+
27
+ echo " export NETBOX_TOKEN=$$ {TOKEN}" >> .bash_profile
Original file line number Diff line number Diff line change
1
+ resource "aws_security_group" "ansible" {
2
+ vpc_id = module. vpc . vpc_id
3
+ }
4
+
5
+ resource "aws_vpc_security_group_egress_rule" "ansible_allow_all_out" {
6
+ security_group_id = aws_security_group. ansible . id
7
+ cidr_ipv4 = " 0.0.0.0/0"
8
+ ip_protocol = " -1"
9
+ }
10
+
11
+ resource "aws_instance" "ansible_instance" {
12
+ ami = data. aws_ssm_parameter . al2023_ami_arm64 . value
13
+ instance_type = " t4g.large"
14
+ subnet_id = module. vpc . public_subnets [0 ]
15
+ vpc_security_group_ids = [aws_security_group . ansible . id ]
16
+ user_data = templatefile (" ${ path . module } /ansible.sh.tpl" , {
17
+ ansible_cfg = file (" ${ path . module } /ansible.cfg" ),
18
+ ansible_nb_inv_yaml = file (" ${ path . module } /ansible_nb_inv.yaml" ),
19
+ netbox_api = aws_instance.nbe_instance.private_ip
20
+ admin_password = var.nbe_admin_password
21
+ })
22
+ associate_public_ip_address = true
23
+ iam_instance_profile = aws_iam_instance_profile. ssm_instance_profile . name
24
+ }
25
+
26
+ output "ansible_ssm_command" {
27
+ value = " aws ssm start-session --target ${ aws_instance . ansible_instance . id } "
28
+ }
Original file line number Diff line number Diff line change
1
+ plugin : netbox.netbox.nb_inventory
2
+ validate_certs : False
3
+ group_by :
4
+ - device_roles
5
+ - sites
You can’t perform that action at this time.
0 commit comments