Course Hero Logo

54 dockercontainer 55 name containername 56 state

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 440 - 444 out of 468 pages.

54docker_container:55name: '{{ container_name }}'56state: absentThe post-tasks clean up unnecessary cruft inside the container (trimming down thesize of the committed image), commit the Docker container to an image (taggeda4d/hubot-slack:latest), and remove the running container.
Chapter 15 - Docker and Ansible415When building from aDockerfile, you can set things like theUSER(the user used torun theCMDorENTRYPOINTin the container) andCMD(the defaults for an executingcontainer) directly. In our case, since we’re not building from aDockerfile, we setthese options usingdocker commit’s-cor--changeoption.Now that we have the main scaffolding in place for building a Docker container,committing an image from that container, and tearing down the container, it’s timeto add the ‘meat’ to our playbook—the role that installs Hubot and its Slack adapter.Building thehubot-slackroleAs with any role, the easiest way to scaffold the necessary files is using theansible-galaxycommand. Create ahubot-slackrole in arolessubdirectory with:ansible-galaxy role init hubot-slackYou can delete some unneeded role directories, namelyfiles,handlers,templates,tests, andvars. If you want, fill in the metadata fields insidemeta/main.yml(this isonly needed if you’re publishing the role on Ansible Galaxy or if you need to haveother roles defined as dependencies, though).Since Hubot isn’t too hard to install, we can do everything we need insidetasks/main.yml.The first thing we need to do is ensure all the required dependencies for generatingour bot are present:1---2- name: Install dependencies.3package:4name: sudo5state: present67- name: Install required Node.js packages.8npm:9name: "{{ item }}"10state: present11global: yes12with_items:
Chapter 15 - Docker and Ansible41613- yo14- generator-hubotBecause we want to be able to run certain commands as ahubotuser later, we’ll needsudopresent so Ansible canbecomethehubotuser. Then we’ll install some requiredependencies—yoandgenerator-hubot, which are used to build the bot. Node.js isalready present inside the container, since we chose to build the container based offthenode:8base image.16- name: Ensure hubot user exists.17user:18name: hubot19create_home: yes20home: "{{ hubot_home }}"It’s best to run Hubot inside an isolated directory, using a dedicated user account, sowe set up ahubotuser account with its own home directory. To make the Hubot roleeasier to adapt, a variable is used for thehubotuser’s home directory. We’ll definethat later indefaults/main.yml.22- name: Generate hubot.23command: >24yo hubot25--owner="{{ hubot_owner }}"26--name="{{ hubot_name }}"27--description="{{ hubot_description }}"28--adapter=slack29--defaults30chdir={{ hubot_home }}31become: yes32become_user: hubotTheyohubotcommand scaffolds all the code necessary to run Hubot, and all theoptions passed in tell the generator to run non-interactively. We will define thedefault rolehubot_vars in this command later indefaults/main.yml.
Chapter 15 - Docker and Ansible41734- name: Remove certain scripts from external-scripts.json.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 468 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A
Tags
Test, Configuration management, Application server, configuration file, Client server, Software configuration management

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture