cloud-init-single-module-fails-to-merge
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Expired
|
Low
|
Unassigned |
Bug Description
I have a yaml file in a local directory (cloud-init.yaml) which contains 2 modules (write_files, runcmd). I am exercising the write_files module using the following command:
$ sudo cloud-init --debug --file cloud-init.yaml single --name cc_write_files
From the debug output I can see that the local file (/home/
2014-05-05 21:25:45,367 - __init__.py[DEBUG]: Merging using located merger 'DictMerger: (method=
2014-05-05 21:25:45,368 - util.py[DEBUG]: Reading from /home/mmorais/
2014-05-05 21:25:45,368 - util.py[DEBUG]: Read 407 bytes from /home/mmorais/
2014-05-05 21:25:45,368 - util.py[DEBUG]: < #cloud-config
2014-05-05 21:25:45,368 - util.py[DEBUG]: < write_files:
2014-05-05 21:25:45,368 - util.py[DEBUG]: < - content: |
2014-05-05 21:25:45,368 - util.py[DEBUG]: < #!/bin/sh
2014-05-05 21:25:45,368 - util.py[DEBUG]: < date +"%s" > /home/y/tmp/now.txt
2014-05-05 21:25:45,368 - util.py[DEBUG]: < path: /home/y/
2014-05-05 21:25:45,368 - util.py[DEBUG]: < permissions: '0755'
2014-05-05 21:25:45,369 - util.py[DEBUG]: < runcmd:
2014-05-05 21:25:45,369 - util.py[DEBUG]: < - ['/home/
2014-05-05 21:25:45,369 - util.py[DEBUG]: Attempting to load yaml from string of length 407 with allowed root types (<type 'dict'>,)
2014-05-05 21:25:45,371 - util.py[DEBUG]: Reading from /var/lib/
2014-05-05 21:25:45,371 - util.py[DEBUG]: Read 0 bytes from /var/lib/
2014-05-05 21:25:45,371 - util.py[DEBUG]: Attempting to load yaml from string of length 0 with allowed root types (<type 'dict'>,)
2014-05-05 21:25:45,371 - util.py[DEBUG]: load_yaml given empty string, returning default
As a workaround I am copying /home/mmorais/
Also note that the command above does not work at all unless I specify *cc_write_files* instead of *write_files*.
I am running cloud-init (0.7.4).
$ cat my.cfg
write_files:
- content: |
hi mom
owner: root:root
path: /tmp/greeting.txt
permissions: '0644'
$ sudo cloud-init --debug --file my.cfg single --name write_files --frequency=always ; echo $?
...
0
$ cat /tmp/greeting.txt
hi mom
So, that generally is working as designed.
I think that 2 things were tripping you up.
A.) you need to say --frequency=always or the write_files will run only with its default frequency (once per instance).
B.) merging in cloud-init with arrays is kind of annoying.
The default merge routine replaces arrays, where as I think you would rather have it append.
In recent versions of cloud-init, you *can* have it append, you just need to change to use cloud-config-jsonp format.
I tried quickly to ge tan example of doing that.. and my attempt looked like this: greeting. txt"}}
$ cat my-patch.cfg
[
{"op": "add", "path": "/write-files/-",
"value": {"content": "hi mom", "path": "/tmp/new-
]
using that fails though.