How to run cloud init modules multiple times, e.g. runcmd, write_files, runcmd

I am using cloud-init to build an Ubuntu 16.04 LTS VM on Azure. The server I want to build will run software installed from a custom repository.

I use the runcmd directive to add the repository, update the apt database and install the package and its dependencies:

runcmd:
  - wget -O - https://nightly.odoo.com/odoo.key | apt-key add -
  - echo "deb http://nightly.odoo.com/10.0/nightly/deb/ ./" | tee /etc/apt/sources.list.d/odoo.list
  - apt update
  - apt install --assume-yes odoo

I then write a custom configuration file using the write_files directive. I am unable to do this before installing the software because the presence of a configuration file triggers an interactive prompt during installation.

What I would then like to do is execute further commands (specifically I want to run certbot to install a Lets Encrypt certificate). I have been unable to find a way to do this.

It is possible to add a second set of runcmd entries, but by default cloud-init will ignore all but the last set.

There are solutions for merging multiple sets of entries together. However, the commands are then all executed together, which is not what I want.

One obvious solution would be to write the configuration file using shell commands rather than using the write_files directive, but really I feel like I am swimming upstream with my entire approach, and that perhaps there is a more straightforward solution to what must be a fairly common requirement.

Any input appreciated.

0
задан 21 May 2018 в 16:43
1 ответ

Это не решает конкретную проблему запуска команд оболочки в разных точках во время выполнения cloud-init, однако решением моей проблемы было использование встроенных функций для добавления подходящих источников:

https://cloudinit.readthedocs.io/en/latest/topics/examples.html#additional-apt-configuration

Думаю, более общий ответ - использовать модуль для всего, что вы можете, используйте runcmd, когда вы придется, и если вам нужно и то, и другое, напишите свой собственный модуль облачной инициализации.

0
ответ дан 5 December 2019 в 06:01

Теги

Похожие вопросы