Re: Any ideas of how to work around the lack of force=yes option in the file module?

2,527 views
Skip to first unread message

crucialfelix

unread,
Mar 17, 2013, 8:41:58 AM3/17/13
to ansible...@googlegroups.com

in this particular case you might add a 

  -   name: Install mysql server
      apt: pkg=mysql-server state=installed
      notify: remove default my.conf

and change the remove default to a handler.
it should only fire when installing the package.

however that seems to have a lot of assumptions.

run a shell script that checks if its a file and moves it away if so



On Saturday, March 16, 2013 6:21:51 PM UTC+1, Matti Kotsalainen wrote:
I like to keep my configuration files under version control. I'm trying to install mysql server via:

        -   name: Install mysql server
            apt: pkg=mysql-server state=installed

        -   name:   Symlink mysql conf
            file:   src=/srv/degen/misc/deploy/my.cnf dest=/etc/mysql/my.cnf state=link
            notify: Restart mysql

I get this error message: refusing to convert between file and link for /srv/degen/misc/deploy/my.cnf

This happens because there is no force option when creating the symlink. I've googled it and it seems like other people have this issue as well: https://github.com/ansible/ansible/pull/1044, but it hasn't been resolved.

One possible solution that I've found is to delete the default my.cnf before I create the symlink, like so:

        -   name: Install mysql server
            apt: pkg=mysql-server state=installed

        -   name:   Remove mysql config file 
            file:   path=/etc/mysql/my.cnf state=absent

        -   name:   Symlink mysql conf
            file:   src=/srv/degen/misc/deploy/my.cnf dest=/etc/mysql/my.cnf state=link
            notify: Restart mysql

But this seems like it goes against the declarative nature of ansible?!

So what is your recommendation of how to solve my usecase - that is get rid of the default my.cnf, and replace it with a symlink?

Matti


Michael DeHaan

unread,
Mar 17, 2013, 9:20:19 AM3/17/13
to ansible...@googlegroups.com
I would likely modify your example do something like this:

- name: Install mysql server
apt: pkg=mysql-server state=installed
register: $installed_mss

- name: Remove mysql config file
file: path=/etc/mysql/my.cnf state=absent
when_changed: $installed_mss

- name: Symlink mysql conf
file: src=/srv/degen/misc/deploy/my.cnf
dest=/etc/mysql/my.cnf state=link
notify: Restart mysql
when_changed: $installed_mss

The reason we don't have file forcing between link and file states (or
file and link) for the most part is that could mean too many different
things about how to resolve that particular confusion, and I'd prefer
if things be explicit.

If done with changed variables (above), it still only runs when needed
and that should be fine.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/
Reply all
Reply to author
Forward
0 new messages