# 實際操作測試2 - Docker容器部署

## Pull an image

```
# Install ansible
sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
# Install pip and docker-py
sudo apt-get install python-pip python-dev build-essential 
sudo pip install --upgrade pip
sudo pip install docker-py
```

## Edit the playbook

```
- hosts: localhost
  become: true # use root user with sudo
  tasks:
  - name : Pull Ubuntu Image
    docker_image:
      name: ubuntu
```

Run ansible-book docker\_pull.yml

```
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting

 [WARNING]:  * Failed to parse /etc/ansible/hosts with yaml plugin: Syntax Error while loading YAML.   did not find expected <document start>  The error appears to be in '/etc/ansible/hosts': line 45, column 1, but may be elsewhere in
the file depending on the exact syntax problem.  The offending line appears to be:  [apache] apache2 ansible_host=syrus@192.168.1.108 ansible_port=22 ^ here

 [WARNING]:  * Failed to parse /etc/ansible/hosts with ini plugin: /etc/ansible/hosts:49: Expected key=value host variable assignment, got: ansible_

 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [localhost] ****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Pull Ubuntu Image] ********************************************************************************************************************************************************************************************************************
 [WARNING]: The value of the "source" option was determined to be "pull". Please set the "source" option explicitly. Autodetection will be removed in Ansible 2.12.

changed: [localhost]

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devops.books.c-k.dev/ansible/how-about-deploying-a-container.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
