aristanetworks / atd-public

23 stars 29 forks source link

Enhancement: add LABPASSPHRASE to .zshrc #827

Open mjbear opened 3 months ago

mjbear commented 3 months ago

Is your feature request related to a problem? Please describe. Feature request (enhancement).

Describe the solution you'd like Add LABPASSPHRASE to the .zshrc after line 41 where XTERM is set to help avoid the stumbling block of an unset environment variable upon opening multiple terminals.

Something along the lines of the below snippet should do it.

&& echo "export LABPASSPHRASE=`awk '/password:/{print $2}' /home/coder/.config/code-server/config.yaml`" >> $HOME/.zshrc

Describe alternatives you've considered We could keep things as they are (manual environment variable instantiation) or automate it a bit more with this enhancement.

Additional context Before I realized (or looked to find that) the ATD lab environment uses Docker containers, I put in a feature enhancement issue on the avd-workshops repo to add the LABPASSPHRASE environment variable to .zshrc. :man_facepalming: :man_shrugging:

:bulb: I plan to submit a PR to cover this suggestion once Arista Engineering weighs in. :heart:

mjbear commented 3 months ago

It dawned on me that I don't (yet) know how soon /home/coder/.config/code-server/config.yaml exists. Crossing my fingers :crossed_fingers: that the file exists early on in the process and this will work. :grin:

It's getting late and I need to dig into this further another day.

mjbear commented 3 months ago

So far I haven't yet found the point at which /home/coder/ ends up receiving its files.

There is the possibility the coder content (including config.yaml) is dropped in via rsync at a later time. Whether or not this is the case, it shouldn't matter as the export command (and nested awk command) would be run when users/students open a Terminal within the coder interface. (By that point all the files, including config.yaml would be present in the ATD instance.)

Feedback welcome.

JulioPDX commented 3 months ago

@networkRob thought here is to always have the environment variable set and available to the ATD user. These can be leveraged in any workshops or guides without requiring the user to manually enter the information

networkRob commented 3 months ago

This request makes sense, I'm just thinking about how to implement this. Within the coder container, we define our volume mounts here: https://github.com/aristanetworks/atd-public/blob/0d056f79dce22cc9d481109bd3a545b9b9641801/nested-labvm/atd-docker/docker-compose.yml#L181

When a lab does startup, we have this script and couple of lines that goes through and updates the lab password with the unique lab password. https://github.com/aristanetworks/atd-public/blob/0d056f79dce22cc9d481109bd3a545b9b9641801/nested-labvm/services/eosStartup/eosStartup.sh#L22

Currently we don't mount the ~/.zshrc file out of the container, so that is purely within that container.

Maybe one possibility is to mount that as an env var into the container.

mjbear commented 3 months ago

Thank you Julio for following up on this! Hello Rob and thank you for sharing some knowledge! :grin:

Ah hah, at line 183 is that config.yaml file being mounted into the container. I'll defer to your experienced opinion on the solution(s).

networkRob commented 3 months ago

I don't think we need to update the .zshrc file within the container.

I think what could be done, similar to the Nautobot container set, is to create an env file, where we put our placeholder of:

LABPASSPHRASE={REPLACE_PWD}

We have scripts that will update that password value when the topology boots up. Then that could be mounted via the docker-compose.yml file as an env_file

mjbear commented 3 months ago

Nice!

(I learn best by seeing and doing so I tracked stuff down in the repo. :grinning:)

https://github.com/aristanetworks/atd-public/blob/0d056f79dce22cc9d481109bd3a545b9b9641801/nested-labvm/atd-docker/nautobot/nbot-local.env

https://github.com/aristanetworks/atd-public/blob/0d056f79dce22cc9d481109bd3a545b9b9641801/nested-labvm/atd-docker/docker-compose.yml#L213