Giter VIP home page Giter VIP logo

ansible-interactive-tutorial's Introduction

ansible-interactive-tutorial

Build Status

Interactive tutorials for Ansible

Prerequisite

Only prerequisite is docker

Requires docker version 1.9+ and tested with 1.12+

If you don't have docker installed, you can also run on http://play-with-docker.com (just click "+ ADD NEW INSTANCE" button and clone this repo there)

How to Run

./tutorial.sh

demo

Clean up

./tutorial.sh --remove

More Details

Tutorials

Almost all of the tutorials are adapted from the great leucos/ansible-tuto repository:

1. Getting Started
2. Basic inventory
3. First modules and facts
4. Groups and variables
5. Playbooks
6. Playbooks, pushing files on nodes
7. Playbooks and failures
8. Playbook conditionals
9. Git module
10. Extending to several hosts
11. Templates
12. Variables again
13. Migrating to roles!
14. Using roles from Ansible Galaxy - Install a Jenkins server
15. Free play

You can run each lesson individually but it is highly encouraged to follow the order as most of them are built on top of the previous one!

Containers

tutorial.sh starts 4 docker containers behind the scenes. 1 for running the tutorial itself and 3 as ansible nodes which behave exactly same as (virtual or physical) machines throughout the tutorial.

ansible.tutorial is an alpine based tutorial container in which ansible and nutsh (a framework for creating interactive command line tutorials) are available.

host0.example.org, host1.example.org and host2.example.org are the Ubuntu 16.04 based containers that act as ansible nodes. These nodes were already provisioned with the ssh key of ansible.tutorial container. So that you don't have to deal with setting up keys.

Port Mapping

There are some checkpoints in the tutorials where you can check and verify your deployments. For this purpose some ports of the containers are exposed as host ports as follows:

Container Container Port Host Port
host0.example.org 80 $HOSTPORT_BASE  
host1.example.org 80 $HOSTPORT_BASE+1
host2.example.org 80 $HOSTPORT_BASE+2
host0.example.org 8080 $HOSTPORT_BASE+3
host1.example.org 30000 $HOSTPORT_BASE+4
host2.example.org 443 $HOSTPORT_BASE+5

HOSTPORT_BASE is set to 42726 by default and can be changed while starting the tutorial (in case any of the consecutive 6 ports is not available) as follows:

./tutorial.sh --remove # Make sure you shut down the previous ones
HOSTPORT_BASE=<some_other_value> ./tutorial.sh

Workspace Directory

ansible-interactive-tutorial/workspace directory on your local machine is mounted as /root/workspace inside the ansible.tutorial container. So, you can use your favorite editor on your local machine to edit files. Editing files is not necessary to follow the lessons though.

ansible-interactive-tutorial's People

Contributors

earlgreyt avatar icecream78 avatar jmnofziger-habana avatar lroellin avatar otaconix avatar spikatrix avatar thde avatar turkenh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-interactive-tutorial's Issues

Nothing happens on 7 ( Playbook conditionals ) step

On 7 step ("Playbook conditionals") in this step

The register keyword records output from the apache2ctl configtest command (exit status, stdout, stderr, ...), and when: result|failed checks if the registered variable (result) contains a 
    failed status. 

    Here we go! Run the following command to execute our playbook:

Lesson - have a failed and ... nothing happens ....
No instructions, no tasks ...

host{0,1,2}.example.org ssh authentication fails

As the subject states, authentication fails when trying to ssh.

Here's a print out of the terminal

~/workspace $ fping host{0,1,2}.example.org
host0.example.org is alive
host1.example.org is alive
host2.example.org is alive



    Cool!

    These hosts were already provisioned with the ssh key of this node. So you don't have to deal with setting up keys and can directly ssh into any of them as root user.

    Try it and don't forget to get back to continue (run exit once you got there):

    ssh host0.example.org

~/workspace $ ssh host0.example.org
The authenticity of host 'host0.example.org (172.18.0.2)' can't be established.
ECDSA key fingerprint is SHA256:GcQIpCuKx9yOfsw5HrxBUdfnAkquoq+NIm6EMoh1io0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'host0.example.org,172.18.0.2' (ECDSA) to the list of known hosts.
Authentication failed.
~/workspace $ ssh host0.example.org
Authentication failed.
~/workspace $ ssh host1.example.org
The authenticity of host 'host1.example.org (172.18.0.3)' can't be established.
ECDSA key fingerprint is SHA256:GcQIpCuKx9yOfsw5HrxBUdfnAkquoq+NIm6EMoh1io0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'host1.example.org,172.18.0.3' (ECDSA) to the list of known hosts.
Authentication failed.
~/workspace $ ssh host2.example.org
The authenticity of host 'host2.example.org (172.18.0.4)' can't be established.
ECDSA key fingerprint is SHA256:GcQIpCuKx9yOfsw5HrxBUdfnAkquoq+NIm6EMoh1io0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'host2.example.org,172.18.0.4' (ECDSA) to the list of known hosts.
Authentication failed.
~/workspace $

Using a Oracle Linux 7 host with docker Docker version 18.09.1-ol, build e32a1bd

docker: invalid reference format: repository name must be lowercase.

OS: Xubuntu 17.04
Docker version: 17.09.0-ce, build afdb6d4 API 1.32

Everything seem fine at first. but at the end given the error and unable to run tutorial:
docker: invalid reference format: repository name must be lowercase.

I had to sudo, since docker doesn't run w/o elevated permissions.

sudo ./tutorial.sh
creating network ansible.tutorial
starting container host0.example.org: mapping hostport 42726 -> container port 80 && hostport 42729 -> container port 8080
Unable to find image 'turkenh/ubuntu-1604-ansible-docker-host:1.0' locally
1.0: Pulling from turkenh/ubuntu-1604-ansible-docker-host
d5c6f90da05d: Pulling fs layer
bbbe761fcb56: Pulling fs layer
7afa5ede606f: Pulling fs layer
f6b7253b56f4: Pulling fs layer
2b8db33536d4: Pulling fs layer
a2b45d4ab2fd: Pulling fs layer
03b1c7fa7980: Pulling fs layer
10a4ee0fd8bb: Pulling fs layer
ad81eaefa5af: Pulling fs layer
751338e06da3: Pulling fs layer
03b1c7fa7980: Waiting
a2b45d4ab2fd: Waiting
10a4ee0fd8bb: Waiting
ad81eaefa5af: Waiting
751338e06da3: Waiting
2b8db33536d4: Waiting
f6b7253b56f4: Waiting
7afa5ede606f: Download complete
bbbe761fcb56: Verifying Checksum
bbbe761fcb56: Download complete
f6b7253b56f4: Verifying Checksum
f6b7253b56f4: Download complete
2b8db33536d4: Download complete
03b1c7fa7980: Download complete
10a4ee0fd8bb: Verifying Checksum
10a4ee0fd8bb: Download complete
ad81eaefa5af: Download complete
751338e06da3: Download complete
d5c6f90da05d: Verifying Checksum
d5c6f90da05d: Download complete
d5c6f90da05d: Pull complete
bbbe761fcb56: Pull complete
7afa5ede606f: Pull complete
f6b7253b56f4: Pull complete
2b8db33536d4: Pull complete
a2b45d4ab2fd: Retrying in 5 seconds
a2b45d4ab2fd: Retrying in 4 seconds
a2b45d4ab2fd: Retrying in 3 seconds
a2b45d4ab2fd: Retrying in 2 seconds
a2b45d4ab2fd: Retrying in 1 second
a2b45d4ab2fd: Download complete
a2b45d4ab2fd: Pull complete
03b1c7fa7980: Pull complete
10a4ee0fd8bb: Pull complete
ad81eaefa5af: Pull complete
751338e06da3: Pull complete
Digest: sha256:84c1c22800da13f28a2a11ad3efc1d208a3c90bcd5b9687eb3ca44ebb449188f
Status: Downloaded newer image for turkenh/ubuntu-1604-ansible-docker-host:1.0
starting container host1.example.org: mapping hostport 42727 -> container port 80 && hostport 42730 -> container port 30000
starting container host2.example.org: mapping hostport 42728 -> container port 80 && hostport 42731 -> container port 443
starting container ansible.tutorial
docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.

Cannot type in lesson prompt

Hi I'm having some trouble with the tutorial

$ docker --version
Docker version 18.09.3, build 774a1f4

When I start ./tutorial.sh I can interact with the menu prompt, but when the lesson is started I cannot type at all.

Private Images?

Seems like we need a username and password to get the images required for the tutorial.

tutorial.sh throws an error

I have done no debugging yet but here is the information that pertains to the event. This may not be a bug at all but rather a system setup issue on my end.

system notes:
Kernel 4.11.12-1-MANJARO
Docker version 17.10.0-ce, build f4ffd2511c

Steps to replicate:
git clone https://github.com/turkenh/ansible-interactive-tutorial.git
cd ansible-interactive-tutorial
./tutorial.sh

output:
./tutorial.sh
starting container host0.example.org: mapping hostport 42726 -> container port 80 && hostport 42729 -> container port 8080
Unable to find image 'turkenh/ubuntu-1604-ansible-docker-host:1.0' locally
1.0: Pulling from turkenh/ubuntu-1604-ansible-docker-host
d5c6f90da05d: Pulling fs layer
bbbe761fcb56: Pulling fs layer
7afa5ede606f: Pulling fs layer
f6b7253b56f4: Pulling fs layer
2b8db33536d4: Pulling fs layer
a2b45d4ab2fd: Pulling fs layer
03b1c7fa7980: Pulling fs layer
10a4ee0fd8bb: Pulling fs layer
ad81eaefa5af: Pulling fs layer
751338e06da3: Pulling fs layer
f6b7253b56f4: Waiting
2b8db33536d4: Waiting
a2b45d4ab2fd: Waiting
03b1c7fa7980: Waiting
10a4ee0fd8bb: Waiting
ad81eaefa5af: Waiting
751338e06da3: Waiting
bbbe761fcb56: Verifying Checksum
bbbe761fcb56: Download complete
7afa5ede606f: Verifying Checksum
7afa5ede606f: Download complete
f6b7253b56f4: Verifying Checksum
f6b7253b56f4: Download complete
2b8db33536d4: Verifying Checksum
2b8db33536d4: Download complete
03b1c7fa7980: Download complete
10a4ee0fd8bb: Download complete
ad81eaefa5af: Download complete
751338e06da3: Verifying Checksum
751338e06da3: Download complete
d5c6f90da05d: Download complete
d5c6f90da05d: Pull complete
bbbe761fcb56: Pull complete
7afa5ede606f: Pull complete
f6b7253b56f4: Pull complete
2b8db33536d4: Pull complete
a2b45d4ab2fd: Verifying Checksum
a2b45d4ab2fd: Download complete
a2b45d4ab2fd: Pull complete
03b1c7fa7980: Pull complete
10a4ee0fd8bb: Pull complete
ad81eaefa5af: Pull complete
751338e06da3: Pull complete
Digest: sha256:84c1c22800da13f28a2a11ad3efc1d208a3c90bcd5b9687eb3ca44ebb449188f
Status: Downloaded newer image for turkenh/ubuntu-1604-ansible-docker-host:1.0
docker: Error response from daemon: oci runtime error: container_linux.go:295: starting container process caused "process_linux.go:399: container init caused "process_linux.go:382: running prestart hook 0 caused \"fork/exec /usr/bin/dockerd (deleted): no such file or directory\""".
Could not start host container. Exiting!

Does not work with podman

This tutorial is incompactible with podman.

[dalius@srpirmas ansible-interactive-tutorial]$ sudo ./tutorial.sh
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: unknown flag: --format
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: unknown flag: --format
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: unknown flag: --format
starting container ansible.tutorial
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.

"sh" command causes "panic: runtime error: slice bounds out of range"

Below is the reproduction on CentOS 8:

/ansible-interactive-tutorial]:606 sudo ./tutorial.sh
starting container ansible.tutorial

== Ansible Interactive Tutorial ==

1) Getting Started
2) Basic inventory
3) First modules and facts
4) Groups and variables
5) Playbooks
6) Playbooks, pushing files on nodes
7) Playbooks and failures
8) Playbook conditionals
9) Git module
10) Extending to several hosts
11) Templates
12) Variables again
13) Migrating to roles!
14) Using roles from Ansible Galaxy - Install a Jenkins server
15) Free play

0) [Exit]

Please select a lesson: 1

== Getting Started ==


    Hello, welcome to the Ansible Interactive Tutorial! 

    This lesson is to make you familiar with the environment. 

    Now, you are inside a docker container on which you have ansible installed. 

    Verify that you have ansible installed by running the following command: 

    ansible --version 

~/workspace $ sh 
panic: runtime error: slice bounds out of range

goroutine 20 [running]:
github.com/turkenh/nutsh/cli.tokenize(0xc420060c00, 0xc420060c60, 0xc420060cc0, 0xc4204610d8)
	/root/go/src/github.com/turkenh/nutsh/cli/tokenizer.go:118 +0xad3
created by github.com/turkenh/nutsh/cli.Spawn
	/root/go/src/github.com/turkenh/nutsh/cli/cli.go:46 +0x2c1

Replace state=installed with state=present

First, let me thank you for your great tutorial, so far it works perfectly.

Do you think you could replace the deprecated form of the apt module state=installed with state=present?
As a beginner it confused me that state=installed was not present in the documentation and only stackoverflow helped.

I can also make a pull request if you'd prefer that.

Lesson 5: Can't complete Apache server installation

Hello.
During the lesson 5 I faced with issue which showed below:

~/workspace $ ansible-playbook -i hosts -l host1.example.org apache.yml 

PLAY [web] **********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************
ok: [host1.example.org]

TASK [Installs apache web server] ***********************************************************************************************************************************************************************************
^C [ERROR]: User interrupted execution

~/workspace $ ansible-playbook -i hosts -l host1.example.org apache.yml 

PLAY [web] **********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************
ok: [host1.example.org]

TASK [Installs apache web server] ***********************************************************************************************************************************************************************************
^CProcess WorkerProcess-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
 [ERROR]: User interrupted execution

How can I solve this?

Broken link in lesson 3: "First modules and facts"

User is prompted to use the copy module. After successfully doing so the user is returned a success message with a prompt to explore the other modules offered by Ansible:

    Please check the output above. 

    Ansible (more accurately copy module executed on the node) replied back a bunch of useful information in JSON format. We'll see how that can be used later. 

    We'll see other useful modules below. Ansible has a huge module list that covers almost anything you can do on a system. 

    Please see the following page: http://docs.ansible.com/ansible/latest/list_of_all_modules.html 

    If you can't find the right module, writing one is pretty easy (it doesn't even have to be Python, it just needs to speak JSON). 

    Please press the "Enter" key to continue! 

The link for the Ansible module list is currently offered as:
http://docs.ansible.com/ansible/latest/list_of_all_modules.html

This link returns an "Oops" 404 page. The link could be updated to following ansible doc page which appears to offer the same information the previous link did:
https://docs.ansible.com/ansible/latest/collections/index_module.html

Thanks!

Issue just to say Thanks)
really helpfull

after selecting menu no shell prompt

Hi,
i used your tutorial yesterday. It is really cool! :)
Today i tried to reset it, first with
git clean -fdx ; git reset --hard ; docker system prune -a ; ./tutorial.sh --remove
and then i restarted it.
now if i enter a menu point the shell prompt does not appear, only after tipping CTRL+C.

any idea?

docker: 'network' is not a docker command. See 'docker --help'.

$ ./tutorial.sh
creating network ansible.tutorial
docker: 'network' is not a docker command. See 'docker --help'.
starting container host0.example.org: mapping hostport 42726 -> container port 80 && hostport 42729 -> container port 8080
docker: --net: invalid net mode: invalid --net: ansible.tutorial. See 'docker run --help'.
Could not start host container. Exiting!

$ docker -v
Docker version 1.6.2, build 7c8fca2

$ cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=17.2
DISTRIB_CODENAME=rafaela
DISTRIB_DESCRIPTION="Linux Mint 17.2 Rafaela"

Level 14 error.

First of all, thanks for this tutorial, i really loved this style of learning, but had some errors at lvl 14, so here is the solution(if you can call it like that :)
In the master container (workspace) go to this file and change the links:
/root/.ansible/roles/geerlingguy.jenkins/vars/Debian.yml

Here you can find valid links to use.
https://pkg.jenkins.io/debian-rc/

[Enhancement] A Feature to save the session ?

Hi Team!
Thanks for such sweet and fun tool, I am really having much fun around with it. Though it would be great if there could be any way to save the progress and resume it later.

Nothing happening after Copy Module on lesson 3

Hello, was just trying out the tutorial and I ran into an issue on lesson 3 First modules and facts. I am not getting any other instructions after running the copy command. Is this an expected behaviour? Attached screenshot below.

Screenshot 2021-07-12 at 3 32 56 PM

Lesson Menu doesn´t show up in Ubuntu 18.04.2 LTS (Bionic Beaver) Subsystem for Windows 10

Hello Turkenh!

Fist of all, thank you very much for writting the tutorial. I am trying to use it in Ubuntu 18.04.2 LTS that comes with Windows 10. As you can see, Docker works fine and starts the containers, however, the Lesson menu doesn´t show up and you can´t pick any lesson, see traces below:

root@Felix-Rodriguez:/mnt/d/Felix/Tech/Ansible/ansible-interactive-tutorial-master# ./tutorial.sh
creating network ansible.tutorial
starting container host0.example.org: mapping hostport 42726 -> container port 80 && hostport 42729 -> container port 8080
starting container host1.example.org: mapping hostport 42727 -> container port 80 && hostport 42730 -> container port 30000
starting container host2.example.org: mapping hostport 42728 -> container port 80 && hostport 42731 -> container port 443
starting container ansible.tutorial

== ==

(Comment - According to the video, the lessons menu should be displayed here, but it's not)

  1. [Exit]

Please select a lesson: 1
(ENTER, nothing happens)

Please select a lesson: 1
(ENTER, nothing happens)

Please select a lesson:

The only selection that works is exit. Do you know why could this be happening?

Thank you very much.

Kind regards.

Minor issue in tutorial 14 - geerlingguy.java is not installed

On tutorial 14) Using roles from Ansible Galaxy - Install a Jenkins server geerlingguy.java I've found that role installation is missing.

Executed commands, as shown in the tutorial:

ansible-galaxy install geerlingguy.jenkins
cat hosts
cat jenkins.yaml
ansible-playbook -i hosts jenkins.yaml

Where the last command shows the following error:

ERROR! the role 'geerlingguy.java' was not found in /root/workspace/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/root/workspace

The error appears to have been in '/root/workspace/jenkins.yaml': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
    - role: geerlingguy.java
      ^ here

One solution could be, changing the role installation step to:

ansible-galaxy install geerlingguy.jenkins geerlingguy.java

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.