Git Product home page Git Product logo

Comments (9)

udondan avatar udondan commented on May 28, 2024

Hi Brady,

you're very welcome to ask all the questions you can think of - no reasons at all to feel sorry. In regards of NetworkToCode... I fear you're mistaking me for someone else. I'm not much of a Slack user and never heard of that channel before.

Answer 1: When using Silo, Ansible is running inside the docker container. That means, if you create a local file, it also is created inside the container. The container is destroyed after the playbook completes, which also results into loss of the files you created during play.

To interact with the filesystem of the parent host, you need to create these files on a Docker volume. In bundle mode there is no default volume (silo.$(whoami)) mounted. But you can easily mount your own volumes as well by creating the file ~/.qos_mgmt. The file name has to match the name of the bundle. Put this content inside:

silo_mount_qos_mgmt() {
  docker volume create qos_mgmt > /dev/null
  echo "--volume 'qos_mgmt:/some/path/here'"
}

This will create a new volume qos_mgmt and mount it to the path /some/path/here. You then can store the files in /some/path/here and they will persist between plays.

I now see how this is not ideal. Ideally you should be able to add this function directly to your bundle. I'll address this in the next release.

Answer 2: You could actually solve this by defining the default inventory in your ansible.cfg:

inventory = netbox.py

But you as well can hardcode any options in the entrypoint file in your bundle directory. At the bottom of the file you can see this line:

run_as_user_with_SSH "/silo/userspace/ansible/bin/ansible-playbook" "$@"

This is the actual ansible-playbook call. The $@ forwards all the parameters you gave to the playbook. You can modify this to your needs, for example:

run_as_user_with_SSH "/silo/userspace/ansible/bin/ansible-playbook" -i netbox.py "$@"

If you also only have a single playbook in the bundle, this is the place where you as well can hardcode this.

I'll leave this ticket open until a better solution for adding a volume in a bundle is available in the next release.

Cheers,
Daniel

from ansible-silo.

udondan avatar udondan commented on May 28, 2024

Silo 2.1.0 is now out which supports above mentioned runner extension from inside the bundle.

You can upgrade your bundle by doing three things:

  1. Update the Silo version in your Dockerfile:
    FROM grpn/ansible-silo:2.1.0
    
  2. Add a new line to the Dockerfile to ADD the new file bundle_extension.sh:
    ADD bundle_extension.sh /silo/bundle_extension.sh
    
  3. Create the file bundle_extension.sh and add below function:
    silo_mount_qos_mgmt() {
      docker volume create qos_mgmt > /dev/null
      echo "--volume 'qos_mgmt:/some/path/here'"
    }

With these modifications in place the path /some/path/here should be persistent between plays. On your first run you most probably will get an error, since docker volumes by default are not world writable. To fix this you can set permissions or ownership per qos_mgmt --shell sudo chown "${UID}:${UID}" /some/path/here or qos_mgmt --shell sudo chmod 777 /some/path/here.

Also make sure to either increase the version of your bundle or delete /tmp/qos_mgmt-runner-*.

Let me know if this works for you.

from ansible-silo.

bdlamprecht avatar bdlamprecht commented on May 28, 2024

I think the idea of enabling volumes in the bundle_extension.sh is great, however, I've tried every which way to get it working per your instructions and the documentation.

I ended up deleting all previous versions of ansible-silo and did a docker pull grpn/ansible-silo:latest. This appeared to grab the correct version:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
grpn/ansible-silo   2.1.0               a75ab6acc179        7 hours ago         307MB

I then created a new bundle called qos-mgmt (notice the hyphen instead of the underscore) by doing the following:

$ ansible-silo --bundle qos-mgmt

$ cd qos-mgmt/playbooks
$ cp -R [MY_PROJECT]/* .

$ ./build 0.0.1
--SNIP--
Successfully built d398e62d6f89
Successfully tagged qos-mgmt:0.0.1

$ docker run --interactive --tty --rm --volume "$HOME/bin:/silo_install_path" qos-mgmt:latest --install
Installing from qos-mgmt 0.0.1:
 - qos-mgmt will be updated
Done

$ qos-mgmt --version
qos-mgmt 0.0.1
ansible-silo 2.1.0
ansible 2.4.2.0

I then tested the "bundle" and it worked just like before (i.e. non-persistent data).

Using the example bundle_extension.sh that is now created automatically with ansible-silo 2.1.0, I altered it to look like this:

qos-mgmt_persistant_storage() {
  local volume="qos-mgmt_persistant_storage"
  docker volume create "${volume}" > /dev/null
  echo "--volume '${volume}:/output'"
}
:

(I'm not quite sure what the : is there, but didn't want to remove it since it existed in the bundle_extension.sh example and I didn't know if it served a purpose or not)

My PBs store all of their generated files in the directory output in the root of their executed directory.

I tried various versions of --volume '${volume}:/playbooks/output since it appeared (from exploring the structure of the container using the --shell bash option) that the root of the container's filesystem included a playbooks directory. However, it was all to no avail, each attempt at running my PB had the same outcome, no persistent data was stored.

However, I did notice that a volume was created:

$ docker volume ls
DRIVER              VOLUME NAME
local               qos-mgmt
local               silo.bl839s

$ docker volume inspect qos-mgmt
[
    {
        "CreatedAt": "2018-01-09T16:22:17-07:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/qos-mgmt/_data",
        "Name": "qos-mgmt",
        "Options": {},
        "Scope": "local"
    }
]

I browsed the directory /var/lib/docker/volumes/qos-mgmt/_data but nothing was there either.

I have a feeling that I'm missing one small but very important detail to get this working as I would like.
Any pointers you can provide would be much appreciated and again, thanks for all of the help thus far.

from ansible-silo.

udondan avatar udondan commented on May 28, 2024

I then created a new bundle called qos-mgmt (notice the hyphen instead of the underscore)

I think that's the issue, I failed to test a bundle with hyphen. Nothing wrong with the hyphen in the bundle name, Silo then just fails to find the function in the bundle_extension.sh.

I just tried it and if you rename the function from qos-mgmt_persistant_storage to qos_mgmt_persistant_storage (hyphen to underscore) it's working.

When you change the bundle content and re-build, make sure to either increase the version number (and then --install with the new image ) or delete the runner script in /tmp: sudo rm -rf /tmp/qos-mgmt-runner*. Otherwise it will not pick up the changes in the extension file.

If this still is not working, please have a look at the debug output. For me it looks like this with the fixed function name:

$ SILO_DEBUG=1 qos-mgmt -i inventory playbook.yml
SILO vars:
 - SILO_DEBUG=1

Requesting runner creation. Starting container with --run.

Executing: /tmp/qos-mgmt-runner-1.0.0 "-i" "inventory" "playbook.yml"
Executing: /usr/bin/docker run --interactive --tty --rm --volume 'qos-mgmt_persistant_storage:/tmp/qos-mgmt'  --hostname "silo.example.com" --volume /var/run/docker.sock:/var/run/docker.sock --privileged  --volume "/home/daniel.schroeder/.ssh:/home/user/._ssh" --volume "/tmp/ssh-BeRxDGJ76Z":"/tmp/ssh-BeRxDGJ76Z" --env SSH_AUTH_SOCK --env USER_NAME="daniel.schroeder" --env USER_ID="1234" "qos-mgmt:1.0.0" "-i" "inventory" "playbook.yml"

It includes the new volume mount: --volume 'qos-mgmt_persistant_storage:/tmp/qos-mgmt'

(I'm not quite sure what the : is there, but didn't want to remove it since it existed in the bundle_extension.sh example and I didn't know if it served a purpose or not

You safely can remove the colon. In bash the : is a noop, doing exactly nothing. It is just there to pass shellcheck tests which complain if there is no actual bash content in a file.

I'll fix the example function in bundle_extension.sh and convert hyphen automatically to underscore.

from ansible-silo.

udondan avatar udondan commented on May 28, 2024

A fix will be added per #51.

from ansible-silo.

udondan avatar udondan commented on May 28, 2024

Silo 2.1.1 now was released including the fix.

from ansible-silo.

bdlamprecht avatar bdlamprecht commented on May 28, 2024

Thanks for releasing updates to silo after every question I ask (makes me feel somewhat boneheaded). 😄

I briefly thought about the hyphen being an issue (especially when dealing with python), but forgot about the thought entirely. However, I believe something else is going.

So as to not worry about issues with hyphens and other special characters, I've decided (at least for now) to use the name qosmgmt going forward.

I can see the volume is being created, but the persistent storage is not functioning the way I expect it to be. Sorry for being so obtuse, but here is what I just tried after upgrading to ansible-silo 2.1.1.

No volumes currently exist:

$ docker volume ls
DRIVER              VOLUME NAME  
$

The shell script creating the volume in docker:

$ cat bundle_extension.sh
qosmgmt_persistant_storage() {
  local volume="qosmgmt_persistant_storage"
  docker volume create "${volume}" > /dev/null
  echo "--volume '${volume}:/playbooks/output'"
}

Building the "bundle":

$ ./build 0.0.5
Sending build context to Docker daemon  1.136MB
Step 1/13 : FROM grpn/ansible-silo:2.1.1
---SNIP---
Successfully built b7aa8a8c650a
Successfully tagged qosmgmt:0.0.5

Installing the "bundle":

$ docker run --interactive --tty --rm --volume "$HOME/bin:/silo_install_path" qosmgmt:latest --install
Installing from qosmgmt 0.0.5:
 - qosmgmt will be updated
Done

Setting debug to yes and running the container:

$ export SILO_DEBUG=1
$ qosmgmt --version
SILO vars:
 - SILO_DEBUG=1

Requesting runner creation. Starting container with --run.

Executing: /tmp/qosmgmt-runner-0.0.5 "--version"
Executing: /usr/bin/docker run --interactive --tty --rm --volume 'qosmgmt_persistant_storage:/playbooks/output'  --hostname "silo.docker-node2.coc.ibm.com" --volume /var/run/docker.sock:/var/run/docker.sock --privileged  --volume "/home/bl839s/.ssh:/home/user/._ssh"  --env USER_NAME="bl839s" --env USER_ID="901000002" "qosmgmt:0.0.5" "--version"

qosmgmt 0.0.5
ansible-silo 2.1.1
ansible 2.4.2.0

Showing the volume was created and the path of it on the local filesystem:

$ docker volume ls
DRIVER              VOLUME NAME
local               qosmgmt_persistant_storage

$ docker volume inspect qosmgmt_persistant_storage
[
    {
        "CreatedAt": "2018-01-15T11:30:30-07:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/qosmgmt_persistant_storage/_data",
        "Name": "qosmgmt_persistant_storage",
        "Options": {},
        "Scope": "local"
    }
]

Browsing the filesystem and adding a temporary file there:

# cd /var/lib/docker/volumes/qosmgmt_persistant_storage/_data

# ll
total 8
drwxr-xr-x 2 root root 4096 Jan 15 11:30 ./
drwxr-xr-x 3 root root 4096 Jan 15 11:30 ../

# touch TEMPFILE

# ll
total 8
drwxr-xr-x 2 root root 4096 Jan 15 11:36 ./
drwxr-xr-x 3 root root 4096 Jan 15 11:30 ../
-rw-r--r-- 1 root root    0 Jan 15 11:36 TEMPFILE

Running the --shell of the "bundle":

$ qosmgmt --shell
SILO vars:
 - SILO_DEBUG=1

Runner file already exists.

Executing: /tmp/qosmgmt-runner-0.0.5 "--shell"
Executing: /usr/bin/docker run --interactive --tty --rm --volume 'qosmgmt_persistant_storage:/playbooks/output'  --hostname "silo.docker-node2.[REMOVED]" --volume /var/run/docker.sock:/var/run/docker.sock --privileged  --volume "/home/bl839s/.ssh:/home/user/._ssh"  --env USER_NAME="bl839s" --env USER_ID="901000002" "qosmgmt:0.0.5" "--shell"

Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
[ansible-silo 2.1.1|~/playbooks]$

In separate session, showing the container running:

$ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
d3b17d3d3d29        qosmgmt:0.0.5       "/silo/entrypoint --…"   12 seconds ago      Up 12 seconds                           gifted_lamport

Showing the "TEMPFILE" which was just created doesn't exist in the mounted volume (the bundle_extension.sh indicates the mount location to be /playbooks/output):

[ansible-silo 2.1.1|~/playbooks]$ cd output/
[ansible-silo 2.1.1|~/playbooks/output]$ ls -l
total 0
[ansible-silo 2.1.1|~/playbooks/output]$

I know it can't be this complicated and I'll keep digging to find out what I'm doing wrong, I'm simply stumped.

from ansible-silo.

bdlamprecht avatar bdlamprecht commented on May 28, 2024

So, from within the shell of the bundle, I just randomly decided to do show the working path with pwd and saw the following:

[ansible-silo 2.1.1|~/playbooks]$ pwd
/home/user/playbooks

Since that is NOT where the volume is mounted at (per the bundle_extension.sh), looked closer.
When looking at the root of the container, I saw the following:

[ansible-silo 2.1.1|~/playbooks/output]$ cd /

[ansible-silo 2.1.1|/]$ ls
bin        etc        lib        mnt        proc       run        silo       sys        usr
dev        home       media      playbooks  root       sbin       srv        tmp        var

[ansible-silo 2.1.1|/]$ cd playbooks/

[ansible-silo 2.1.1|/playbooks]$ ls -l
total 4
drwxr-xr-x    2 root     root          4096 Jan 15 18:36 output

[ansible-silo 2.1.1|/playbooks]$ cd output/

[ansible-silo 2.1.1|/playbooks/output]$ ls
TEMPFILE

There is the temporary file! 🤦‍♂️

I suppose my problem was not understanding that the working directory of the "bundle" was /home/user/playbooks/. Stupid error on my part; I knew it was something really simple! Perhaps that could be explicitly called out in the documentation somewhere.

I was able to get it to work by changing the location in the bundle_extension.sh to the following:

cat ./bundle_extension.sh
qosmgmt_persistant_storage() {
  local volume="qosmgmt_persistant_storage"
  docker volume create "${volume}" > /dev/null
  echo "--volume '${volume}:/home/user/playbooks/output'"
}

Again, my apologizes for the trouble, and much gratitude for the time that was spent.

from ansible-silo.

udondan avatar udondan commented on May 28, 2024

Aye, yes, that was a simple misunderstanding then. The path in the example function was just showing the mounting and was not aiming to be in the same directory as the playbooks. You're right, the working dir inside the container should be mentioned in the docs. I will take care of it when I find some time.

from ansible-silo.

Related Issues (20)

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.