Skip to content

Commit aab0a22

Browse files
authored
Merge pull request Juniper#416 from rsmekala/awx
Adds ansible-junos-awx project
2 parents ba70d62 + 2f34b56 commit aab0a22

File tree

3 files changed

+703
-0
lines changed

3 files changed

+703
-0
lines changed

ansible-junos-awx/Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
PWD = $(shell pwd)
2+
UNAME_S := $(shell uname -s)
3+
4+
ifeq ($(UNAME_S),Darwin)
5+
SED := sed -i ''
6+
else
7+
SED := sed -i
8+
endif
9+
10+
include Makefile.variable
11+
12+
all:prequisite virtual-env ansible-awx docker-start docker-exec ## install ansible-junos-awx
13+
14+
15+
.PHONY: prequisite
16+
prequisite:
17+
pip install virtualenv
18+
rm -rf ./awx ./awx-env
19+
20+
.PHONY: virtual-env
21+
virtual-env:
22+
virtualenv awx-env --no-site-packages
23+
. awx-env/bin/activate && \
24+
pip install ansible docker-py
25+
26+
.PHONY: ansible-awx
27+
ansible-awx:
28+
. awx-env/bin/activate && \
29+
git clone https://github.com/ansible/awx.git --single-branch --depth 1
30+
31+
.PHONY: docker-start
32+
docker-start:
33+
ifneq '$(PROJECT_DATA_DIR)' ''
34+
mkdir -p $(PROJECT_DATA_DIR)
35+
@${SED} '/project_data_dir/s/^#//g' $(PWD)/awx/installer/inventory
36+
@${SED} 's|project_data_dir=.*|project_data_dir=$(PROJECT_DATA_DIR)|g' $(PWD)/awx/installer/inventory
37+
endif
38+
ifneq '$(AWX_TASK_TAG)' ''
39+
@${SED} 's/dockerhub_version=.*/dockerhub_version=$(AWX_TASK_TAG)/g' $(PWD)/awx/installer/inventory
40+
endif
41+
ifneq '$(POSTGRES_DATA_DIR)' ''
42+
@${SED} 's|postgres_data_dir=.*|postgres_data_dir=$(POSTGRES_DATA_DIR)|g' $(PWD)/awx/installer/inventory
43+
@mkdir -p ${POSTGRES_DATA_DIR}/pg_snapshots && touch ${POSTGRES_DATA_DIR}/pg_snapshots/.keep
44+
@mkdir -p ${POSTGRES_DATA_DIR}/pg_replslot && touch ${POSTGRES_DATA_DIR}/pg_replslot/.keep
45+
@mkdir -p ${POSTGRES_DATA_DIR}/pg_stat_tmp && touch ${POSTGRES_DATA_DIR}/pg_stat_tmp/.keep
46+
@mkdir -p ${POSTGRES_DATA_DIR}/pg_stat && touch ${POSTGRES_DATA_DIR}/pg_stat/.keep
47+
@mkdir -p ${POSTGRES_DATA_DIR}/pg_twophase && touch ${POSTGRES_DATA_DIR}/pg_twophase/.keep
48+
@mkdir -p ${POSTGRES_DATA_DIR}/pg_tblspc && touch ${POSTGRES_DATA_DIR}/pg_tblspc/.keep
49+
endif
50+
ifneq '$(HOST_FILE)' ''
51+
cp $(HOST_FILE) $(strip $(PROJECT_DATA_DIR))/hosts
52+
endif
53+
54+
. awx-env/bin/activate && \
55+
ansible-playbook -i $(PWD)/awx/installer/inventory $(PWD)/awx/installer/install.yml
56+
sleep 120
57+
58+
.PHONY: docker-exec
59+
docker-exec:
60+
docker exec -it awx_task pip install jsnapy jxmlease junos-eznc
61+
docker exec -it awx_task ansible-galaxy install Juniper.junos,$(ANSIBLE_JUNOS_VERSION) -p /etc/ansible/roles
62+
docker exec -it awx_task /bin/bash -c 'sed -i '/roles_path/s/^#//g' /etc/ansible/ansible.cfg'
63+
ifneq '$(HOST_FILE)' ''
64+
curl -u admin:password --noproxy '*' http://localhost/api/v2/inventories/ --header "Content-Type: application/json" -x POST -d '{"name":"$(INVENTORY_NAME)" , "organization": 1}'
65+
docker exec -it awx_task /bin/bash -c 'awx-manage inventory_import --source=/var/lib/awx/projects/hosts --inventory-name=$(INVENTORY_NAME) --overwrite'
66+
endif
67+
68+
.PHONY: docker-stop
69+
docker-stop: ## stop the docker
70+
docker stop awx_task
71+
docker stop awx_web
72+
docker stop memcached
73+
docker stop rabbitmq
74+
docker stop postgres
75+
76+
.PHONY: docker-remove
77+
docker-remove: docker-stop ##clean the docker
78+
docker rm awx_task
79+
docker rm awx_web
80+
docker rm memcached
81+
docker rm rabbitmq
82+
docker rm postgres
83+
84+
clean: prequisite ## clean the project
85+
docker system prune -f
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PROJECT_DATA_DIR =
2+
AWX_TASK_TAG =
3+
POSTGRES_DATA_DIR =
4+
ANSIBLE_JUNOS_VERSION =
5+
HOST_FILE =
6+
INVENTORY_NAME =

0 commit comments

Comments
 (0)