From aa5d7b59ecde62299146d7f6511b8e94db1ef907 Mon Sep 17 00:00:00 2001 From: Tung Leo Date: Sat, 16 Mar 2024 17:07:36 +0700 Subject: [PATCH] doc: ansible user guide --- docs/troubleshooting/TROUBLESHOOTING.md | 12 ++++--- docs/usage/ansible_usage.md | 45 +++++++++++++++++++++++++ docs/usage/python_usage.md | 30 ++++++++++------- 3 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 docs/usage/ansible_usage.md diff --git a/docs/troubleshooting/TROUBLESHOOTING.md b/docs/troubleshooting/TROUBLESHOOTING.md index 417f985..2af51bd 100644 --- a/docs/troubleshooting/TROUBLESHOOTING.md +++ b/docs/troubleshooting/TROUBLESHOOTING.md @@ -1,10 +1,14 @@ # Most common error +#### docker-on-wsl2-very-slow + - -- exec /usr/local/bin/kubectl: exec format error -See: +#### exec /usr/local/bin/kubectl: exec format error + +- See: +Check architecure: dpkg --print-architecture -- Check architecure: dpkg --print-architecture +#### docker: Error response from daemon: Conflict. The container name "/my_devops_toolkit" is already in use by container -- docker: Error response from daemon: Conflict. The container name "/my_devops_toolkit" is already in use by container +- Fix by using anotehr name or delete the current container diff --git a/docs/usage/ansible_usage.md b/docs/usage/ansible_usage.md new file mode 100644 index 0000000..aa9ec6d --- /dev/null +++ b/docs/usage/ansible_usage.md @@ -0,0 +1,45 @@ +# Use python in the devops-toolkit + +To use the existing container isntead of creating one, use `docker exec` command instead of `docker run` + +```bash +docker exec -it my_devops_toolkit /bin/bash +``` + +## Use case 1: Run python sample code provided in the container + +```bash +docker run --rm --network host -it devops-toolkit:latest +# You now in the container terminal +python3 samples/python/rectangle_area_calculator.py +``` + +## Use case 2: Clone external code to container + +```bash +docker run --rm --network host -it devops-toolkit:latest +# You now in the container terminal + +# Clone code +mkdir python_workspace +cd python_workspace +git clone https://github.com/geekcomputers/Python.git + +# Now run your cloned script +cd Python +python3 Day_of_week.py +``` + +## Use case 3: Mount external code to container + +Clone the code to the host then mount to container + +```bash +# Clone code on the host +docker run --rm -v "$(pwd)":/root/python_workspace --network host -it devops-toolkit:latest +# Run the python code as usual +``` + +## Troubleshooting + +- For any issues, check [this reference](../troubleshooting/TROUBLESHOOTING.md) diff --git a/docs/usage/python_usage.md b/docs/usage/python_usage.md index e90798b..d49499a 100644 --- a/docs/usage/python_usage.md +++ b/docs/usage/python_usage.md @@ -3,39 +3,43 @@ To use the existing container isntead of creating one, use `docker exec` command instead of `docker run` ```bash +# Given that we have 'my_devops_toolkit' start before docker exec -it my_devops_toolkit /bin/bash ``` -## Run python sample code provided in the container +## Use case 1: Run Ansible sample code provided in the container ```bash -docker run --name my_devops_toolkit --network host -it devops-toolkit:latest +docker run --rm --network host -it devops-toolkit:latest # You now in the container terminal -python3 samples/python/rectangle_area_calculator.py +ansible-playbook samples/ansible/check_os.yml ``` -## Clone external code to container +## Use case 2: Clone external code to container ```bash -docker run --name my_devops_toolkit --network host -it devops-toolkit:latest +docker run --rm --network host -it devops-toolkit:latest # You now in the container terminal # Clone code -mkdir python_workspace -cd python_workspace -git clone https://github.com/geekcomputers/Python.git +mkdir ansible_workspace +cd ansible_workspace +git clone https://github.com/ansible/ansible-examples.git # Now run your cloned script -cd Python -python3 Day_of_week.py +cd ansible-examples +ansible-playbook ``` -## Mount external code to container +## Use case 3: Mount external code to container Clone the code to the host then mount to container ```bash -# Clone code on the host -docker run --name my_devops_toolkit -v "$(pwd)":/root/python_workspace --network host -it devops-toolkit:latest +docker run --rm -v "$(pwd)":/root/ansible-examples --network host -it devops-toolkit:latest # Run the python code as usual ``` + +## Troubleshooting + +- For any issues, check [this reference](../troubleshooting/TROUBLESHOOTING.md)