Skip to content

Commit

Permalink
doc: ansible user guide
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq committed Mar 16, 2024
1 parent 65bd316 commit aa5d7b5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
12 changes: 8 additions & 4 deletions docs/troubleshooting/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Most common error

#### docker-on-wsl2-very-slow

- <https://stackoverflow.com/questions/62154016/docker-on-wsl2-very-slow>

- exec /usr/local/bin/kubectl: exec format error
See: <https://stackoverflow.com/questions/73398714/docker-fails-when-building-on-m1-macs-exec-usr-local-bin-docker-entrypoint-sh>
#### exec /usr/local/bin/kubectl: exec format error

- See: <https://stackoverflow.com/questions/73398714/docker-fails-when-building-on-m1-macs-exec-usr-local-bin-docker-entrypoint-sh>
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
45 changes: 45 additions & 0 deletions docs/usage/ansible_usage.md
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 17 additions & 13 deletions docs/usage/python_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <YOUR_PLAYBOOK_CMD>
```

## 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)

0 comments on commit aa5d7b5

Please sign in to comment.