cloud-init-single-module-fails-to-merge
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| | cloud-init |
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).
| Scott Moser (smoser) wrote : | #1 |
| Scott Moser (smoser) wrote : | #2 |
try again, same fail, but
$ cat my-patch.cfg
#cloud-config-jsonp
[
{"op": "add", "path": "/write-files/-",
"value": {"content": "hi mom", "path": "/tmp/new-
]
| Scott Moser (smoser) wrote : | #3 |
relavent log from the attempt looks like:
$ sudo cloud-init --debug --file my-patch.cfg single --name write_files --frequency=always
2014-08-21 21:03:28,925 - util.py[DEBUG]: Reading from /home/ubuntu/
False)
2014-08-21 21:03:28,925 - util.py[DEBUG]: Read 134 bytes from /home/ubuntu/
2014-08-21 21:03:28,925 - util.py[DEBUG]: Attempting to load yaml from string of length 134 with allowed root types (<type 'dict'>,)
2014-08-21 21:03:28,927 - util.py[WARNING]: Failed loading yaml blob
2014-08-21 21:03:28,927 - util.py[DEBUG]: Failed loading yaml blob
Traceback (most recent call last):
File "/usr/lib/
(allowed, type_utils.
TypeError: Yaml load allows (<type 'dict'>,) root types, but got list instead
2014-08-21 21:03:28,927 - util.py[DEBUG]: Reading from /var/lib/
| Joshua Harlow (harlowja) wrote : | #4 |
So try the following, this should work:
[harlowja@
#cloud-config
merge_how: "dict(allow_
write_files:
- content: "#!/bin/sh"
path: /home/y/
permissions: '0755'
[harlowja@
#cloud-config
write_files:
- content: |
hi mom
owner: root:root
path: /tmp/greeting.txt
permissions: '0644'
| Scott Moser (smoser) wrote : | #5 |
and above, harlowja's 'merge-how' could also occur inside the 'my.cfg' (i expect, not tested). but thats the goal.
| Scott Moser (smoser) wrote : | #6 |
As this is right now, i'm going to make treat this bug as:
"cloud-init --config=foo.cfg single" does not allow 'cloud-
| Scott Moser (smoser) wrote : | #7 |
unless marco raises otherwise.
| Changed in cloud-init: | |
| status: | New → Confirmed |
| importance: | Undecided → Low |


$ 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.