{
    "version": "https:\/\/jsonfeed.org\/version\/1.1",
    "title": "Discover Docker, K8s and Hashicorp Nomad with Maksym Prokopov: posts tagged ansible",
    "_rss_description": "The blog about containerisation, virtual machines and useful shell snippets and findings",
    "_rss_language": "en",
    "_itunes_email": "",
    "_itunes_categories_xml": "",
    "_itunes_image": "",
    "_itunes_explicit": "",
    "home_page_url": "https:\/\/blog.it-premium.com.ua\/tags\/ansible\/",
    "feed_url": "https:\/\/blog.it-premium.com.ua\/tags\/ansible\/json\/",
    "icon": false,
    "authors": [
        {
            "name": "Maksym Prokopov",
            "url": "https:\/\/blog.it-premium.com.ua\/",
            "avatar": false
        }
    ],
    "items": [
        {
            "id": "235",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/ansible-remove-false-variables-from-environment\/",
            "title": "Ansible remove False variables from environment",
            "content_html": "<p>Use the following code snippet:<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">telegram:\n  enabled: False\n\nEnv:\n  - TELEGRAM_NOTIFICATION={{ telegram.enabled | ternary(&#039;true&#039;, None)}}<\/code><\/pre><p>In this way False value evaluates to None and as outcome you’ll get empty TELEGRAM_NOTIFICATION variable<\/p>\n",
            "date_published": "2021-09-14T08:38:01+01:00",
            "date_modified": "2021-09-14T08:37:56+01:00",
            "tags": [
                "ansible"
            ],
            "_date_published_rfc2822": "Tue, 14 Sep 2021 08:38:01 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "235",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "224",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/ansible-add-entries-to-htpassword\/",
            "title": "Ansible add entries to .htpassword",
            "content_html": "<p>There are several ways to do this:<\/p>\n<ol start=\"1\">\n<li>Use template action and use template file<\/li>\n<li>Use array of entries and loop with lininfile command<\/li>\n<li>Use <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/collections\/community\/general\/htpasswd_module.html\">https:\/\/docs.ansible.com\/ansible\/latest\/collections\/community\/general\/htpasswd_module.html<\/a> htpasswd module.<\/li>\n<\/ol>\n<p>I decided to go with approach #2.<br \/>\nin variables<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">htpasswd:\n  - user1:password1\n  - user2:password2<\/code><\/pre><p>in the playbook<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">- name: set password file\n      lineinfile:\n        path: &quot;{{ webroot }}\/shared\/.htpasswd&quot;\n        line: &quot;{{ item }}&quot;\n        create: yes\n      when: oxid.configuration == &quot;production&quot;\n      loop: &quot;{{ htpasswd }}&quot;<\/code><\/pre>",
            "date_published": "2020-09-29T11:49:00+01:00",
            "date_modified": "2020-09-29T11:48:55+01:00",
            "tags": [
                "ansible"
            ],
            "_date_published_rfc2822": "Tue, 29 Sep 2020 11:49:00 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "224",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "215",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/ansible-vault-quick-encryption\/",
            "title": "ansible vault quick encryption",
            "content_html": "<p>it was convenient for me to use zsh function for the string encryption:<\/p>\n<p>add this to .zshrc<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">vault() {\n\techo -n $1 | ansible-vault encrypt_string --vault-id=myvault\n}<\/code><\/pre><p>and use like this<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">vault my-password<\/code><\/pre><p>output should be similar to this<\/p>\n<pre>\nReading plaintext input from stdin. (ctrl-d to end input)\n!vault |\n          $ANSIBLE_VAULT;1.1;AES256\n          39383538336133613537376463373062363639343761633365666530313363343766663662336530\n          6637336536383438333038623865386636383737393165340a663236336463306261386466326262\n          31333664393130313734303230356364626335346336363430303036633962343536353137376665\n          3464363163346433350a653230336636643562363030383363336166636365313133343563393261\n          38396530616261616338626161363133323430323361623164393466333038326637\nEncryption successful\n<\/pre>\n",
            "date_published": "2020-03-22T10:06:47+01:00",
            "date_modified": "2020-03-22T10:07:33+01:00",
            "tags": [
                "ansible"
            ],
            "_date_published_rfc2822": "Sun, 22 Mar 2020 10:06:47 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "215",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "175",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/ansible-docker-service-module-issue-and-dependency-hell\/",
            "title": "Ansible, docker_service module issue and dependency hell",
            "content_html": "<p>I struggled with deploying web services via Ansible to staging CoreOS host and that’s something that looks like a hell!<\/p>\n<p>I received one error, then another with just simple-simple steps like<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">- name: IT-Premium docker-compose deploy\n  hosts: coreos\n  tasks:\n    - name: Install docker-py\n      pip: name=docker-py executable=\/home\/core\/bin\/pip\n\n    - name: Install PyYAML\n      pip: name=PyYAML executable=\/home\/core\/bin\/pip\n\n    - name: Install docker-compose\n      pip: name=docker-compose executable=\/home\/core\/bin\/pip version=1.9.0\n\n    - name: Creates it-premium directory\n      file: path=\/home\/core\/it-premium state=directory\n\n    - name: copy docker-compose.yml\n      copy: src=.\/docker-compose.yml dest=\/home\/core\/it-premium\/docker-compose.yml\n      tags: deploy\n\n    - name: copy sqlite\n      copy: src=.\/sqlite dest=\/home\/core\/it-premium\/ mode=0644\n      tags: deploy\n\n    - name: docker registry login\n      docker_login:\n        registry: &quot;registry.it-expert.com.ua&quot;\n        username: nexus\n        password: &quot;{{gitlab_password}}&quot;\n\n    - name: pull images\n      docker_image:\n        name: registry.it-expert.com.ua\/nexus\/it-premium\n        state: present\n\n    - name: launch it-premium docker-compose with 2 containers\n      tags: step1\n      docker_service:\n        project_src: it-premium\n        state: present\n        build: no\n      register: output\n\n    - debug:\n        var: output<\/code><\/pre><p>You can notice version of docker-compose 1.9.0, which is supplied there. That’s because of issue with<br \/>\nError: cannot import name ‘IPAMConfig’<br \/>\nthrown by docker_service.<\/p>\n<p>And here is why <a href=\"https:\/\/github.com\/ansible\/ansible\/issues\/20492\">https:\/\/github.com\/ansible\/ansible\/issues\/20492<\/a><\/p>\n<p>This is due to your docker-compose version.<br \/>\nThe docker-py package has been renamed into docker in version 2.0 (<a href=\"https:\/\/github.com\/docker\/docker-py\/releases\/tag\/2.0.0).\">https:\/\/github.com\/docker\/docker-py\/releases\/tag\/2.0.0).<\/a> And in this version, Docker.Client has been renamed into docker.APIClient.<br \/>\nDocker-compose 1.10+ now requires docker instead of docker-py. And due to his name the docker package is before the docker-py one in the PYTHONPATH leading to the import error.<br \/>\nA workaround is to downgrade your docker-compose version to 1.9.0 the time the Ansible docker_container module updates its dependencies from docker-py to docker.<\/p>\n<p>That’s something like “piss on you, dirty user, because we do not care about backward compatibility”.<\/p>\n<p>Because when you change something, it is like delete old state and introduce new one instead. And when you delete something, that could broke anything that relies on state.<\/p>\n<p>How to do instead? Just ADD something new without removal. Call it with new namespace, new function  name and just use!<\/p>\n",
            "date_published": "2017-02-09T12:07:02+01:00",
            "date_modified": "2017-02-09T12:07:33+01:00",
            "tags": [
                "ansible",
                "docker"
            ],
            "_date_published_rfc2822": "Thu, 09 Feb 2017 12:07:02 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "175",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "167",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/docker-py-version-is-1-10-6-minimum-version-required-is-1-7-0\/",
            "title": "docker-py version is 1.10.6. Minimum version required is 1.7.0.",
            "content_html": "<p>You need to upgrade ansible to version 2.2.0.0<\/p>\n<p>via brew:<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">brew update &amp;&amp; brew upbrage ansible<\/code><\/pre><p>or via pip:<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">pip install --upgrade ansible<\/code><\/pre>",
            "date_published": "2016-12-12T09:55:05+01:00",
            "date_modified": "2016-12-12T09:55:02+01:00",
            "tags": [
                "ansible"
            ],
            "_date_published_rfc2822": "Mon, 12 Dec 2016 09:55:05 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "167",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "147",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/docker-compose-recipe-for-ansible\/",
            "title": "docker-compose recipe for ansible",
            "content_html": "<pre class=\"e2-text-code\"><code class=\"\">- name: install docker-compose\n  become: yes\n  file: path=\/opt\/bin state=directory mode=0755\n\n- name: get docker-compose url\n  shell: curl -s https:\/\/api.github.com\/repos\/docker\/compose\/releases\/latest | jq -r &#039;.assets[].browser_download_url | select(contains(&quot;Linux&quot;) and contains(&quot;x86_64&quot;))&#039;\n  register: url_info\n\n- name: fetch docker-compose\n  become: yes\n  get_url: url=&quot;{{url_info.stdout}}&quot; dest=\/opt\/bin\/docker-compose mode=0755<\/code><\/pre>",
            "date_published": "2016-09-15T14:14:20+01:00",
            "date_modified": "2016-09-15T14:14:18+01:00",
            "tags": [
                "ansible",
                "docker"
            ],
            "_date_published_rfc2822": "Thu, 15 Sep 2016 14:14:20 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "147",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "136",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/snyatie-bekapa-iz-mysql-konteynera-pri-pomoschi-ansible\/",
            "title": "Снятие бекапа из mysql контейнера при помощи Ansible",
            "content_html": "<p>Вот простой рецепт:<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">- name: backup mysql from container\n  gather_facts: no\n  vars:\n    - db_container: container_db_1\n    - image: mysql:5.6\n    - db:\n        name: database_name\n        user: root\n        password: root\n    - dump_file: .\/dump-latest.sql\n  tasks:\n    - name: run backup container\n      shell: &quot;docker run --rm --link {{db_container}}:db --entrypoint \\&quot;\/usr\/bin\/mysqldump\\&quot; {{image}} -hdb -u{{db.user}} -p{{db.password}} {{db.name}}&quot;\n      register: output\n\n    - name: copy output\n      local_action: copy content=&quot;{{ output.stdout }}&quot; dest=&quot;{{dump_file}}&quot;<\/code><\/pre><p>Работает БЕЗ создания файлов на удаленном хосте, помимо, конечно, временного контейнера.<\/p>\n<script type=\"text\/javascript\" src=\"https:\/\/asciinema.org\/a\/680nbb59m9ko2ptrdkvf79123.js\" id=\"asciicast-680nbb59m9ko2ptrdkvf79123\" async><\/script>\n",
            "date_published": "2016-07-21T12:19:21+01:00",
            "date_modified": "2016-07-21T13:14:38+01:00",
            "tags": [
                "ansible",
                "docker",
                "mysql"
            ],
            "_date_published_rfc2822": "Thu, 21 Jul 2016 12:19:21 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "136",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "128",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/ustanovka-docker-compose-na-coreos-cherez-ansible\/",
            "title": "Установка docker-compose на CoreOS через Ansible",
            "content_html": "<p>Разработал для этого очень простой рецепт по мотивам <a href=\"http:\/\/blog.it-premium.com.ua\/all\/oneliner-for-docker-compose-install-for-coreos\/\">предыдущей заметки<\/a>:<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">\n- name: install docker-compose to coreos\n  hosts: coreos\n  gather_facts: no\n  tasks:\n    - name: install docker-compose\n      become: yes\n      file: path=\/opt\/bin state=directory mode=0755\n\n    - name: get docker-compose url\n      shell: curl -s https:\/\/api.github.com\/repos\/docker\/compose\/releases\/latest | jq -r &#039;.assets[].browser_download_url | select(contains(&quot;Linux&quot;) and contains(&quot;x86_64&quot;))&#039;\n      register: url_info\n\n    - name: fetch docker-compose\n      become: yes\n      get_url: url=&quot;{{url_info.stdout}}&quot; dest=\/opt\/bin\/docker-compose mode=0755\n&lt;code&gt;\n\nскрипт найдет url и скачает самую свежую версию и установит аттрибуты для корректного запуска из \/opt\/bin\n\nнапоминаю, \/opt\/bin переживает перезагрузки и является persistent каталогом в CoreOS.<\/code><\/pre>",
            "date_published": "2016-07-19T10:17:55+01:00",
            "date_modified": "2016-07-19T10:18:22+01:00",
            "tags": [
                "ansible",
                "coreos"
            ],
            "_date_published_rfc2822": "Tue, 19 Jul 2016 10:17:55 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "128",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "121",
            "url": "https:\/\/blog.it-premium.com.ua\/all\/kak-ispolzovat-ansible-s-coreos\/",
            "title": "Как использовать Ansible с CoreOS?",
            "content_html": "<p>Ведь для использования Ansible необходимо иметь python интерпретатор<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">&quot;module_stdout&quot;: &quot;\/bin\/sh: \/usr\/bin\/python: No such file or directory\\r\\n&quot;,<\/code><\/pre><p>к счастью у ansible есть режим так называемой raw работы, без использования интерпретатора python, который и даст установить python и необходимые модули.<\/p>\n<p>запускаем<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">ansible-galaxy install defunctzombie.coreos-bootstrap -p .\/roles<\/code><\/pre><p>и создаем рецепт bootstrap.yml<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">- hosts: coreos\n  gather_facts: False\n  roles:\n    - defunctzombie.coreos-bootstrap<\/code><\/pre><p>и запускаем для нужного хоста coreos<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">ansible-playbook bootstrap.yml<\/code><\/pre><p>это загрузит соответствующую версию мини-питона и даст ansible возможность выполняться на хосте как обычно.<\/p>\n<p>Я использую macOS, поэтому пришлось ствить ansible из pip пакетов командой<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">sudo pip install ansible\npip install --upgrade setuptools --user python\npip install --upgrade pyasn1 --user python<\/code><\/pre><p>Update:<br \/>\nв новой версии ansible вместо пакета docker предлагается использовать docker-container и docker-image, поэтому <a href=\"мануал\"><a href=\"https:\/\/coreos.com\/blog\/managing-coreos-with-ansible\/\">https:\/\/coreos.com\/blog\/managing-coreos-with-ansible\/<\/a><\/a> немного устарел.<\/p>\n<p>Вот мой работоспособный site.yml<\/p>\n<pre class=\"e2-text-code\"><code class=\"\">- name: Nginx Example\n  hosts: coreos\n  tasks:\n    ##- name: Start etcd\n      #service: name=etcd.service state=started\n\n    - name: Install docker-py\n      pip: name=docker-py executable=\/home\/core\/bin\/pip\n\n    - name: Install PyYAML\n      pip: name=PyYAML executable=\/home\/core\/bin\/pip\n\n    - name: Install docker-compose\n      pip: name=docker-compose executable=\/home\/core\/bin\/pip\n\n    - name: launch nginx container\n      docker_container:\n        name: &quot;nginx-proxy&quot;\n        image: &quot;jwilder\/nginx-proxy&quot;\n        ports: &quot;80:80&quot;\n        restart_policy: always\n        state: started\n        volumes:\n          - \/var\/run\/docker.sock:\/tmp\/docker.sock:ro\n\n    - name: copy docker-compose.yml\n      copy: src=.\/Sites\/it-premium\/docker-compose.prod.yml dest=\/home\/core\/it-premium\/docker-compose.yml\n      tags: deploy\n\n    - name: copy sqlite\n      copy: src=.\/Sites\/it-premium\/sqlite dest=\/home\/core\/it-premium\/ directory_mode=yes mode=0644\n      tags: deploy\n\n    - name: launch it-premium docker-compose with 2 containers\n      docker_service:\n        project_src: it-premium\n        build: no\n      register: output\n\n    - debug: var=output\n    - assert:\n        that: &quot;not output.changed &quot;<\/code><\/pre><p>здесь я копирую docker-compose.yml подготовленный для продакшена и sqlite3 продакшен базу из бекапа.<\/p>\n",
            "date_published": "2016-07-13T11:46:19+01:00",
            "date_modified": "2016-07-13T14:28:49+01:00",
            "tags": [
                "ansible",
                "coreos"
            ],
            "_date_published_rfc2822": "Wed, 13 Jul 2016 11:46:19 +0100",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "121",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        }
    ],
    "_e2_version": 4134,
    "_e2_ua_string": "Aegea 11.3 (v4134)"
}