emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Beginning with org-babel.
@ 2022-02-25  1:20 Steven Harris
  2022-02-25  2:08 ` William Denton
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Harris @ 2022-02-25  1:20 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1213 bytes --]

Hi All

Ansible is a system configuration-management tool that is based on
"playbooks".  These are collections of mostly YAML files, but also Jinja2
templates and unix configuration files.  To execute one needs to run a unix
shell command with a python virtualenv set up and usually some environment
variables set.

Painfully much of this lives fragmented in a nested directory structure,
many of the files in which are named "main.yml".   Sometimes  the same
information has to be set in two places with incompatible formats , such as
a config file and an environment variable.

I am trying to bring some literate programming to bear on this can of worms
so have reached for Babel.  It's my first use of it.

The current problem is that I have a config file that I want to substitute
a value into.  I want the conf-mode highlighting.  Conf is not a
programming language of course, just a text format.

I'm trying something like

#+begin_src conf :tangle yes :noweb yes
  [defaults]
  private_key_file = <<ssh_private_key_file>>
#+end_src

I have tried something similar to the SQL comment example in the
documentation to no avail and also setting :var headers. How can I
substitute a value here?

Cheers

Steven

[-- Attachment #2: Type: text/html, Size: 1426 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Beginning with org-babel.
  2022-02-25  1:20 Beginning with org-babel Steven Harris
@ 2022-02-25  2:08 ` William Denton
  0 siblings, 0 replies; 2+ messages in thread
From: William Denton @ 2022-02-25  2:08 UTC (permalink / raw)
  To: Steven Harris; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2112 bytes --]

On 25 February 2022, Steven Harris wrote:

> The current problem is that I have a config file that I want to substitute
> a value into.  I want the conf-mode highlighting.  Conf is not a
> programming language of course, just a text format.
>
> I'm trying something like
>
> #+begin_src conf :tangle yes :noweb yes
>  [defaults]
>  private_key_file = <<ssh_private_key_file>>
> #+end_src
>
> I have tried something similar to the SQL comment example in the
> documentation to no avail and also setting :var headers. How can I
> substitute a value here?

I think there are a few different ways, but they depend on Org knowing about the 
language of the source block (as I realized after writing most of this, and 
deciding I'd send it along anyway in case it's helpful):

One way I do it is like so, first with defining a variable.

#+NAME: RUBY_VERSION
| 3.1.1 |

Then, in a source block, call in the variable with :var, like so:

#+begin_src shell :tangle conforg/scripts/ruby-install-personal.sh :shebang "#!/bin/bash" :var RUBY_VERSION=RUBY_VERSION
rbenv install --verbose $RUBY_VERSION
rbenv global $RUBY_VERSION ~/conforg/scripts/ruby-install-gems.sh
echo "Now run bundle install where needed."
#+end_src

I'm using the RUBY_VERSION variable name in two places: first on its own in Org, 
then in the shell script as an environment variable that is set to the value of 
the Org variable.  No point in using two different variable names for this, I 
thought.  But in other cases one would want to.

(This is from Conforguration,¹ my system for setting up my dot files and some 
languages or services I want to run from source.)

But Org knows about shell scripts and can pass variables in to them (like it can 
with SQL), and Org doesn't know about INI files or other config files the same 
way.  So (unless I'm mistaken) this method won't work.

However, surely there's another way ...

Bill

¹ https://github.com/wdenton/conforguration

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-25  2:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25  1:20 Beginning with org-babel Steven Harris
2022-02-25  2:08 ` William Denton

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).