3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DockerでWindowsを操作できるAnsibleコンテナを構築する

Posted at

CentOS7のDockerイメージを取得

$ docker pull centos:centos7
centos7: Pulling from library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for centos:centos7

イメージが取得できました。

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              centos7             1e1148e4cc2c        2 months ago        202MB

コンテナを作成して起動する

$ docker run -it -d --name ansible centos:centos7
7e7004684726b5e5cb2269c39a4ae0c727f723c74a9ea4ccdecc40bf6b2fc716

正常に起動しています。

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
7e7004684726        centos:centos7      "/bin/bash"         46 seconds ago      Up 44 seconds                           ansible

コンテナに入る

$ docker exec -it ansible /bin/bash
[root@7e7004684726 /]#

sshをインストール

[root@7e7004684726 /]# yum install -y openssh-server openssh-clients sshpass

pywinrmをインストール

AnsibleでWindowsを操作するにはpywinrmが必要です。
まずはpythonのバージョンを確認。

[root@7e7004684726 /]# python --version
Python 2.7.5

Python 2.7.5はpipが付属していないので、以下のコマンドでpipをインストールします。

[root@7e7004684726 /]# curl https://bootstrap.pypa.io/get-pip.py | python
[root@7e7004684726 /]# pip --version
pip 19.0.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)

最新版のpipがインストールできたので、pywinrmをインストールします。

[root@7e7004684726 /]# pip install pywinrm
[root@7e7004684726 /]# pip list | grep pywinrm
pywinrm             0.3.0

Ansibleをインストール

[root@7e7004684726 /]# yum install -y epel-release
[root@7e7004684726 /]# yum install -y ansible
[root@7e7004684726 /]# ansible --version
ansible 2.7.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

Windowsを操作できるAnsibleコンテナが完成しました!

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?