First time working with Ansible. I have a playbook that sets up wordpress on Ubuntu Trusty and Nginx / MySQL.
I am trying to get the extraction of the wordpress.latest.tar.gz as part of root www folder. So what I want is:
/var/www
- wp-admin
- wp-content
- wp-includes
When I point the extract command to /var/www
I get:
ok: [XXX.XX.XX.XXX] => {"changed": false, "msg": "skipped, since /var/www exists"}
When I point it to var/www/wordpress
(which does not exist), it works and creates the folder.
My task syntax (that works but places wordpress in its own folder) is:
- name: "Extract archive"
sudo: yes
unarchive: "src=/srv/wordpress.latest.tar.gz
dest=/var/www copy=no
owner=www-data
group=www-data
creates=/var/www/wordpress"
I have tried the syntax below but it skips the extraction per above desciption.
- name: "Extract archive"
sudo: yes
unarchive: "src=/srv/wordpress.latest.tar.gz
dest=/var/www copy=no
owner=www-data
group=www-data
creates=/var/www"
What have I misunderstood? Thanks!
There are some caveats before I answer:
But first, let's give something else a go. This option doesn't use any terminal and works only with the tools you have, but I'd do it in a another directory to make sure you don't mess things up.
I think if you remove the creates=/var/www
it may work for you. The reason it may be failing is because the dir is already there, so it's trying to keep you safe. Since you have specified the destination directory anyway, just go with that.
To test it you could first create a temp dir under /var/www
so that you have the following path that exists: /var/www/temp123
.
Then create your playbook with the following options:
- name: "Extract archive"
sudo: yes
unarchive: "src=/srv/wordpress.latest.tar.gz
dest=/var/www/temp123 copy=no
owner=www-data
group=www-data
creates=/var/www/temp123"
If you get the same error, we're on track.
Now recreate the playbook without the creates
"play" (pun intended) so that it looks like this:
- name: "Extract archive"
sudo: yes
unarchive: "src=/srv/wordpress.latest.tar.gz
dest=/var/www/temp123 copy=no
owner=www-data
group=www-data"
If that works as expected, go ahead and now remove the dest: temp
play option.
Your final play should look like:
- name: "Extract archive"
sudo: yes
unarchive: "src=/srv/wordpress.latest.tar.gz
dest=/var/www copy=no
owner=www-data
group=www-data"
I hope this helps
Don't forget to remove all the temp work as you.
If that didn't work, you could always just try doing it yourself:
at the terminal and in that temp directory:
mv * ..
you may then remove that directory
If you have the file on the server already, change into your/var/www
directory and:
tar -xzvpf /srv/wordpress.latest.tar.gz
x - extract
z - uncompress
v - verbose (see the ouput—this flag is optional)
p - preserve file permissions (see note)
f - the file we're extracting
note: I'm not sure what file permissions will be inside the archive
but I would expect they're set for the webserver already.
If they're not, you could always issue:
chown -R www-data:www-data /var/www/
In the absence of a direct answer already here, I'm only posting this to get you on your way. Again, I haven't used Ansible or am familiar with it. But installing WordPress yourself is not a difficult task if you want to breakaway and give it a go. Although I don't know the extent of the automation Ansible provides and will apologise if doing it this way just doesn't help your cause
Good luck.