Last active
April 8, 2024 19:30
-
-
Save nbigot/b74a908e2f5a3aa2190de191e9ec4505 to your computer and use it in GitHub Desktop.
Ansible playbook AWS - install docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ansible playbook AWS - install docker | |
--- | |
- name: "AWS - Install docker" | |
hosts: aws-docker-vms | |
become: yes | |
tasks: | |
- name: Update all packages | |
yum: | |
name: '*' | |
state: latest | |
update_only: yes | |
- name: Ensure a list of yum packages are installed | |
yum: | |
name: "{{ packages }}" | |
state: latest | |
update_cache: yes | |
vars: | |
packages: | |
- python-pip | |
- yum-utils | |
- device-mapper-persistent-data | |
- lvm2 | |
- amazon-linux-extras | |
- name: Add extras repository | |
shell: yum-config-manager --enable extras | |
- name: Install docker-ce (centos) via amazon-linux-extras packages | |
shell: "amazon-linux-extras install docker=18.06.1 -y" | |
- name: Enable Docker CE service at startup | |
service: | |
name: docker | |
state: started | |
enabled: yes | |
- name: Ensure Python pip packages are installed | |
pip: | |
name: "{{ packages }}" | |
vars: | |
packages: | |
- boto | |
- boto3 | |
- docker-compose |
Thanks.
Having problem with 'Ensure Python pip packages are installed' task:
The remote host with amazon-linux2 OS uses python2 as default interpreter and as a result the task fails. Here is the log:
This is an old configuration that worked some years ago,
I've solved the problem by creating a new one (gist) :
"Ansible playbook AWS - install docker (2021)"
https://gist.github.com/nbigot/3f066b1bb1aef2334788bbbe1b431bfd
This is an old configuration that works some years ago,
I've solved the problem by creating a new one (gist) :"Ansible playbook AWS - install docker (2021)"
https://gist.github.com/nbigot/3f066b1bb1aef2334788bbbe1b431bfd
This one works perfect. Thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.
Having problem with 'Ensure Python pip packages are installed' task:
The remote host with amazon-linux2 OS uses python2 as default interpreter and as a result the task fails. Here is the log:
fatal: [ip-10-100-1-45.eu-central-1.compute.internal]: FAILED! => {"changed": false, "cmd": ["/bin/pip2", "install", "boto", "boto3", "docker-compose"], "msg": "stdout: Collecting boto\n Downloading https://files.pythonhosted.org/packages/23/10/c0b78c27298029e4454a472a1919bde20cb182dab1662cec7f2ca1dcc523/boto-2.49.0-py2.py3-none-any.whl (1.4MB)\nCollecting boto3\n Downloading https://files.pythonhosted.org/packages/7a/1e/570e2446e97bac3d348d0bc6cbf8ac28997ddbef3d97c052f1c476ff48bb/boto3-1.17.49.tar.gz (99kB)\nCollecting docker-compose\n Downloading https://files.pythonhosted.org/packages/43/bf/a9fe1f4b6e0f2ceac7eb7e2dab2fd03edd2fd5ffa8cd90d55ba1453af8b7/docker_compose-1.26.2-py2.py3-none-any.whl (139kB)\nCollecting botocore<1.21.0,>=1.20.49 (from boto3)\n Downloading https://files.pythonhosted.org/packages/68/59/6e28ce58206039ad2592992b75ee79a8f9dbc902a9704373ddacc4f96300/botocore-1.20.49-py2.py3-none-any.whl (7.4MB)\nRequirement already satisfied: jmespath<1.0.0,>=0.7.1 in /usr/lib/python2.7/site-packages (from boto3)\nRequirement already satisfied: s3transfer<0.4.0,>=0.3.0 in /usr/lib/python2.7/site-packages (from boto3)\nCollecting backports.shutil-get-terminal-size==1.0.0; python_version < \"3.3\" (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/7d/cd/1750d6c35fe86d35f8562091737907f234b78fdffab42b29c72b1dd861f4/backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl\nCollecting docker[ssh]<5,>=4.2.2 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/c4/22/410313ad554477e87ec406d38d85f810e61ddb0d2fc44e64994857476de9/docker-4.4.4-py2.py3-none-any.whl (147kB)\nCollecting subprocess32<4,>=3.5.4; python_version < \"3.2\" (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/32/c8/564be4d12629b912ea431f1a50eb8b3b9d00f1a0b1ceff17f266be190007/subprocess32-3.5.4.tar.gz (97kB)\nCollecting texttable<2,>=0.9.0 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/06/f5/46201c428aebe0eecfa83df66bf3e6caa29659dbac5a56ddfd83cae0d4a4/texttable-1.6.3-py2.py3-none-any.whl\nRequirement already satisfied: jsonschema<4,>=2.5.1 in /usr/lib/python2.7/site-packages (from docker-compose)\nCollecting distro<2,>=1.5.0 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/25/b7/b3c4270a11414cb22c6352ebc7a83aaa3712043be29daa05018fd5a5c956/distro-1.5.0-py2.py3-none-any.whl\nCollecting requests<3,>=2.20.0 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/29/c1/24814557f1d22c56d50280771a17307e6bf87b70727d975fd6b2ce6b014a/requests-2.25.1-py2.py3-none-any.whl (61kB)\nCollecting websocket-client<1,>=0.32.0 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/08/33/80e0d4f60e84a1ddd9a03f340be1065a2a363c47ce65c4bd3bae65ce9631/websocket_client-0.58.0-py2.py3-none-any.whl (61kB)\nRequirement already satisfied: PyYAML<6,>=3.10 in /usr/lib64/python2.7/site-packages (from docker-compose)\nCollecting cached-property<2,>=1.2.0 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/48/19/f2090f7dad41e225c7f2326e4cfe6fff49e57dedb5b53636c9551f86b069/cached_property-1.5.2-py2.py3-none-any.whl\nRequirement already satisfied: enum34<2,>=1.0.4; python_version < \"3.4\" in /usr/lib/python2.7/site-packages (from docker-compose)\nRequirement already satisfied: backports.ssl-match-hostname<4,>=3.5; python_version < \"3.5\" in /usr/lib/python2.7/site-packages (from docker-compose)\nCollecting docopt<1,>=0.6.1 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz\nRequirement already satisfied: six<2,>=1.3.0 in /usr/lib/python2.7/site-packages (from docker-compose)\nRequirement already satisfied: ipaddress<2,>=1.0.16; python_version < \"3.3\" in /usr/lib/python2.7/site-packages (from docker-compose)\nCollecting dockerpty<1,>=0.4.1 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/8d/ee/e9ecce4c32204a6738e0a5d5883d3413794d7498fe8b06f44becc028d3ba/dockerpty-0.4.1.tar.gz\nCollecting python-dotenv<1,>=0.13.0 (from docker-compose)\n Downloading https://files.pythonhosted.org/packages/86/62/aacbd1489fc6026c9278e9fd5cfdd49c5b1b5375d3c97a624e8f8f999eb2/python_dotenv-0.17.0-py2.py3-none-any.whl\nRequirement already satisfied: urllib3<1.27,>=1.25.4 in /usr/lib/python2.7/site-packages (from botocore<1.21.0,>=1.20.49->boto3)\nRequirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/lib/python2.7/site-packages (from botocore<1.21.0,>=1.20.49->boto3)\nRequirement already satisfied: futures<4.0.0,>=2.2.0 in /usr/lib/python2.7/site-packages (from s3transfer<0.4.0,>=0.3.0->boto3)\nCollecting paramiko>=2.4.2; extra == \"ssh\" (from docker[ssh]<5,>=4.2.2->docker-compose)\n Downloading https://files.pythonhosted.org/packages/95/19/124e9287b43e6ff3ebb9cdea3e5e8e88475a873c05ccdf8b7e20d2c4201e/paramiko-2.7.2-py2.py3-none-any.whl (206kB)\nRequirement already satisfied: repoze.lru in /usr/lib/python2.7/site-packages (from jsonschema<4,>=2.5.1->docker-compose)\nCollecting certifi>=2017.4.17 (from requests<3,>=2.20.0->docker-compose)\n Downloading https://files.pythonhosted.org/packages/5e/a0/5f06e1e1d463903cf0c0eebeb751791119ed7a4b3737fdc9a77f1cdfb51f/certifi-2020.12.5-py2.py3-none-any.whl (147kB)\nCollecting idna<3,>=2.5 (from requests<3,>=2.20.0->docker-compose)\n Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)\nCollecting chardet<5,>=3.0.2 (from requests<3,>=2.20.0->docker-compose)\n Downloading https://files.pythonhosted.org/packages/19/c7/fa589626997dd07bd87d9269342ccb74b1720384a4d739a1872bd84fbe68/chardet-4.0.0-py2.py3-none-any.whl (178kB)\nCollecting typing; python_version < \"3.5\" (from python-dotenv<1,>=0.13.0->docker-compose)\n Downloading https://files.pythonhosted.org/packages/3b/c0/e44213fcb799eac02881e2485724ba5b0914600bc9df6ed922e364fdc059/typing-3.7.4.3-py2-none-any.whl\nCollecting bcrypt>=3.1.3 (from paramiko>=2.4.2; extra == \"ssh\"->docker[ssh]<5,>=4.2.2->docker-compose)\n Downloading https://files.pythonhosted.org/packages/ad/36/9a0227d048e98409f012570f7bef8a8c2373b9c9c5dfbf82963cbae05ede/bcrypt-3.1.7-cp27-cp27mu-manylinux1_x86_64.whl (59kB)\nCollecting pynacl>=1.0.1 (from paramiko>=2.4.2; extra == \"ssh\"->docker[ssh]<5,>=4.2.2->docker-compose)\n Downloading https://files.pythonhosted.org/packages/de/63/bb36279da38df643c6df3a8a389f29a6ff4a8854468f4c9b9d925b27d57d/PyNaCl-1.4.0-cp27-cp27mu-manylinux1_x86_64.whl (964kB)\nCollecting cryptography>=2.5 (from paramiko>=2.4.2; extra == \"ssh\"->docker[ssh]<5,>=4.2.2->docker-compose)\n Downloading https://files.pythonhosted.org/packages/86/41/44173175d378c9e3a73294bb33c73725f7726def5ce267af6bd11b72eb23/cryptography-3.3.2-cp27-cp27mu-manylinux1_x86_64.whl (2.7MB)\nRequirement already satisfied: cffi>=1.1 in /usr/lib64/python2.7/site-packages (from bcrypt>=3.1.3->paramiko>=2.4.2; extra == \"ssh\"->docker[ssh]<5,>=4.2.2->docker-compose)\nRequirement already satisfied: pycparser in /usr/lib/python2.7/site-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko>=2.4.2; extra == \"ssh\"->docker[ssh]<5,>=4.2.2->docker-compose)\nInstalling collected packages: boto, botocore, boto3, backports.shutil-get-terminal-size, certifi, idna, chardet, requests, websocket-client, bcrypt, pynacl, cryptography, paramiko, docker, subprocess32, texttable, distro, cached-property, docopt, dockerpty, typing, python-dotenv, docker-compose\n Found existing installation: botocore 1.18.6\n Uninstalling botocore-1.18.6:\n Successfully uninstalled botocore-1.18.6\n Running setup.py install for boto3: started\n Running setup.py install for boto3: finished with status 'done'\n Found existing installation: idna 2.4\n Uninstalling idna-2.4:\n Successfully uninstalled idna-2.4\n Found existing installation: chardet 2.2.1\n Uninstalling chardet-2.2.1:\n Successfully uninstalled chardet-2.2.1\n Found existing installation: requests 2.6.0\n Uninstalling requests-2.6.0:\n Successfully uninstalled requests-2.6.0\n Found existing installation: cryptography 1.7.2\n Uninstalling cryptography-1.7.2:\n Successfully uninstalled cryptography-1.7.2\n Running setup.py install for subprocess32: started\n Running setup.py install for subprocess32: finished with status 'error'\n Complete output from command /usr/bin/python2 -u -c \"import setuptools, tokenize;__file__='/tmp/pip-build-IDgYeU/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\\r\\n', '\\n');f.close();exec(compile(code, __file__, 'exec'))\" install --record /tmp/pip-Qtt8QD-record/install-record.txt --single-version-externally-managed --compile:\n running install\n running build\n running build_py\n creating build\n creating build/lib.linux-x86_64-2.7\n copying subprocess32.py -> build/lib.linux-x86_64-2.7\n running build_ext\n running build_configure\n checking for gcc... no\n checking for cc... no\n checking for cl.exe... no\n configure: error: in
/tmp/pip-build-IDgYeU/subprocess32':\n configure: error: no acceptable C compiler found in $PATH\n Seeconfig.log' for more details\n Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n File \"/tmp/pip-build-IDgYeU/subprocess32/setup.py\", line 120, in <module>\n main()\n File \"/tmp/pip-build-IDgYeU/subprocess32/setup.py\", line 114, in main\n 'Programming Language :: Python :: Implementation :: CPython',\n File \"/usr/lib/python2.7/site-packages/setuptools/__init__.py\", line 129, in setup\n return distutils.core.setup(**attrs)\n File \"/usr/lib64/python2.7/distutils/core.py\", line 151, in setup\n dist.run_commands()\n File \"/usr/lib64/python2.7/distutils/dist.py\", line 953, in run_commands\n self.run_command(cmd)\n File \"/usr/lib64/python2.7/distutils/dist.py\", line 972, in run_command\n cmd_obj.run()\n File \"/usr/lib/python2.7/site-packages/setuptools/command/install.py\", line 61, in run\n return orig.install.run(self)\n File \"/usr/lib64/python2.7/distutils/command/install.py\", line 563, in run\n self.run_command('build')\n File \"/usr/lib64/python2.7/distutils/cmd.py\", line 326, in run_command\n self.distribution.run_command(command)\n File \"/usr/lib64/python2.7/distutils/dist.py\", line 972, in run_command\n cmd_obj.run()\n File \"/usr/lib64/python2.7/distutils/command/build.py\", line 127, in run\n self.run_command(cmd_name)\n File \"/usr/lib64/python2.7/distutils/cmd.py\", line 326, in run_command\n self.distribution.run_command(command)\n File \"/usr/lib64/python2.7/distutils/dist.py\", line 972, in run_command\n cmd_obj.run()\n File \"/tmp/pip-build-IDgYeU/subprocess32/setup.py\", line 41, in run\n self.run_command(command)\n File \"/usr/lib64/python2.7/distutils/cmd.py\", line 326, in run_command\n self.distribution.run_command(command)\n File \"/usr/lib64/python2.7/distutils/dist.py\", line 972, in run_command\n cmd_obj.run()\n File \"/tmp/pip-build-IDgYeU/subprocess32/setup.py\", line 26, in run\n raise RuntimeError(configure_command + ' failed.')\n RuntimeError: sh ./configure failed.\n \n ----------------------------------------\n\n:stderr: WARNING: Running pip install with root privileges is generally not a good idea. Try
pip2 install --userinstead.\n DEPRECATION: Uninstalling a distutils installed project (requests) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.\nCommand \"/usr/bin/python2 -u -c \"import setuptools, tokenize;__file__='/tmp/pip-build-IDgYeU/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\\r\\n', '\\n');f.close();exec(compile(code, __file__, 'exec'))\" install --record /tmp/pip-Qtt8QD-record/install-record.txt --single-version-externally-managed --compile\" failed with error code 1 in /tmp/pip-build-IDgYeU/subprocess32/\n"}
I've tried to install python3 and add
executable: pip3
parameterbut the task still fails with
"Unable to find any of pip3 to use. pip needs to be installed."
message.Although these packages are successfully installed if i do it manually using pip3 on host-machine