Create directory

Bug #1666446 reported by Vincent Legoll
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Invalid
Undecided
Unassigned

Bug Description

Cloud-init has writefiles, but it looks like it does not have the capability to create directories.

how is mixing

runcmd:
 - mkdir /home/toto/bin

and

write_files:
 - content: |
        #!/bin/sh
        echo "Hello world!"

    path: /home/toto/bin/hw.sh
    permissions: '0755'

going to work ?

Is runcmd garanteed to happen before write_files ?
What about a "users" section ?

This is the same kind of problem that is reported here:
https://bugs.launchpad.net/cloud-init/+bug/1486113

Revision history for this message
Joshua Powers (powersj) wrote :

Thank you for taking the time to report this bug. In an effort to keep
an up-to-date and valid list of bugs to work on, I have reviewed this
report verifying it still requires effort and occurs on a supported
version of Ubuntu.

Write-files is able to create the path for the file it needs to
create. Consider the following example:

userdata.yaml:
#cloud-config
write_files:
  - path: /root/dir1/dir2/file
    permissions: '0640'
    content: my file
    encoding: file

This should write a file to /root/dir1/dir2/file and will be
required to create the dir1 and dir2 directories.

$ lxc init ubuntu-daily:x x
$ lxc config set x user.user-data - < userdata.yaml
$ lxc start x
# go install tree
$ lxc exec x -- tree
.
└── dir1
    └── dir2
        └── file

The actual code that is run is below, where we check that
the path exists and if not use os.makedirs to generate it:
https://github.com/cloud-init/cloud-init/blob/master/cloudinit/util.py#L1492

I am marking this incomplete as I believe the feature works as expected. If
you disagree please feel free to say otherwise and provide additional
details or scenarios as to why.

Changed in cloud-init:
status: New → Incomplete
Revision history for this message
VinceLe (legoll) wrote :

Ok
Which permissions the created directories have ?

Changed in cloud-init:
status: Incomplete → Invalid
Revision history for this message
Joshua Powers (powersj) wrote :

drwxr-xr-x 3 root root 3 Aug 25 16:24 dir1
drwxr-xr-x 2 root root 3 Aug 25 16:24 dir2
-rw-r----- 1 root root 7 Aug 25 16:24 file

Which aligns with my cloud-config:
    permissions: '0640'

Revision history for this message
VinceLe (legoll) wrote :

That does look 0755 to me

Revision history for this message
Joshua Powers (powersj) wrote :

The permissions in the YAML apply to the end file it is creating, not the directories that may or may not need to be created as well.

Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.