File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5656 - name : Run Ansible Playbook
5757 run : |
5858 ansible-playbook -i inventory.ini setup.yml \
59- --extra-vars "node_username =${{ secrets.NODE_USERNAME }} \
60- node_password =${{ secrets.NODE_PASSWORD }} \
61- secret_message ='${{ secrets.SECRET_MESSAGE }}'"
59+ --extra-vars "mongo_uri =${{ secrets.MONGO_URI }} \
60+ mongo_initdb_root_username =${{ secrets.MONGO_INITDB_ROOT_USERNAME }} \
61+ mongo_initdb_root_password ='${{ secrets.MONGO_INITDB_ROOT_PASSWORD }}'"
6262 env :
6363 ANSIBLE_HOST_KEY_CHECKING : " False"
Original file line number Diff line number Diff line change 66 version : main
77 force : yes
88
9- - name : Build step
10- command : npm install
11- args :
12- chdir : " {{ app_path }}/server"
9+ - name : Create .env file for Docker Compose
10+ ansible.builtin.template :
11+ src : .env.j2
12+ dest : " {{ app_path }}/server/.env"
13+ owner : root
14+ group : root
15+ mode : ' 0600'
1316
14- - name : Pull server image
15- community.docker.docker_image :
16- name : therealpad/my-node-app
17- source : pull
18-
19- - name : Build image and with build args
20- community.docker.docker_image :
21- name : " {{ app_name }}"
22- build :
23- path : " {{ app_path }}/server"
24- source : build
25-
26- - name : Run Node.js container
27- community.docker.docker_container :
28- name : my-node-app
29- image : " {{ app_name }}"
30- state : started
31- restart_policy : always
32- ports :
33- - " 3000:3000"
34- env :
35- PORT : " 3000"
36- USERNAME : " {{ node_username }}"
37- PASSWORD : " {{ node_password }}"
38- SECRET_MESSAGE : " {{ secret_message }}"
17+ - name : Start Node.js and MongoDB containers with Docker Compose
18+ community.docker.docker_compose_v2 :
19+ project_src : " {{ app_path }}/server"
20+ build : always
21+ state : present
22+ environment :
23+ PORT : " {{ node_app_port }}"
24+ MONGO_URI : " {{ mongo_uri }}"
25+ MONGO_INITDB_ROOT_USERNAME : " {{ mongo_initdb_root_username }}"
26+ MONGO_INITDB_ROOT_PASSWORD : " {{ mongo_initdb_root_password }}"
Original file line number Diff line number Diff line change 1+ PORT={{ node_app_port }}
2+ MONGO_URI={{ mongo_uri }}
3+ MONGO_INITDB_ROOT_USERNAME={{ mongo_initdb_root_username }}
4+ MONGO_INITDB_ROOT_PASSWORD={{ mongo_initdb_root_password }}
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ app_name: nodejs-service
22app_repo : " https://github.com/DevOps-PA-resume/Multi-Container-Application"
33app_path : " /var/www/nodejs-service"
44node_app_port : 3000
5- node_username : " admin"
6- node_password : " password "
7- secret_message : " c kool ansible (multi container application) "
5+ mongo_uri : " mongodb://root:password@mongodb:27017/todoapp?authSource= admin"
6+ mongo_initdb_root_username : root
7+ mongo_initdb_root_password : password
Original file line number Diff line number Diff line change 1616 - docker.io
1717 state : present
1818
19+ - name : Ensure the Docker CLI plugin directory exists
20+ ansible.builtin.file :
21+ path : /usr/local/lib/docker/cli-plugins
22+ state : directory
23+ mode : ' 0755'
24+
25+ - name : Download the Docker Compose V2 binary as a plugin
26+ ansible.builtin.get_url :
27+ # Use the same URL you had
28+ url : " https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-{{ ansible_system }}-{{ ansible_architecture }}"
29+ # IMPORTANT: Change the destination to the plugin directory
30+ dest : " /usr/local/lib/docker/cli-plugins/docker-compose"
31+ mode : ' 0755' # Set permissions to be executable
You can’t perform that action at this time.
0 commit comments