-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add state=present to file module (rather than state=touch) #7490
Comments
This can be done with: copy: content="" dest=/path/to/file force=no # plus optional args like mode, etc |
Is there a way of specifying owner and permissions with |
All of the |
@mpdehaan but |
@illenseer copy also takes those same owner/permissions/etc. attributes. As I noted above, there is an open issue to reflect that in the documentation. |
@jimi-c yes, I know, but with |
It appears that I'm late to this discussion. My current workaround is to combine the command and file modules. (This is with ansible-1.8.2, latest in pypi.)
Which would be much nicer if there was a file: state=present. Requirements:
I believe that this is much closer to the state=file behaviour, except that the outcome isn't dependent on the prior existence (or not) of the path. |
I have to agree... state=present would be nice. I'm using state=touch, but that always shows as "changed" in the output, when nothing useful has actually changed. touching when not necessary isn't clean, and neither is stringing other commands together to wind up with the result you could (and should be able to) get from one. Please do add this. |
@mpdehaan I'd vote for that too =/ I mean your described method is a hack. |
Same here: +1 for the |
+ 1. I would love to see that option available 'out-of-the-box' rather than implementing 'ugly' hacks. |
+1. I too am implementing @bencord0's hack. |
+1 to state=present. ensuring the existence of some file is very much a common operation. |
+1 to state=present (linked issue: ansible/ansible-modules-core#170) |
Any way to get this re-opened? This seems like a pretty common need, and using "copy" doesn't ensure that the mode/owner is set correctly. |
- As suggested in ansible/ansible#7490 - file: state=present would be better
Could you please tell me what is the current official solution (not hack), if someone wants
This should be a oneliner I believe, but we've only got closed issues and no correct, full, official solution. Thank you. |
@Petrox, mpdehaan is no longer affiliated with the project. The official method is still state=touch. If you do not want the task to show up as changed use I am going to go ahead and lock this thread. If anyone has any further questions, please direct them to the mailing list. |
This can be done in Ansible >= 2.7.0 by preserving both modification and access time: - file:
path: /tmp/empty
state: touch
modification_time: preserve
access_time: preserve |
Issue Type: Feature Idea
Ansible Version: ansible 1.5.5
Environment: Linux
Summary:
cf discussion on #4097. Although
state=touch
works pretty well, something calledstate=present
would be more useful for (what I think is) a very common use case.Steps To Reproduce: n/a
Expected Results: n/a
Actual Results: n/a
The example is: making sure that a log file is present, and has the correct perms to be written to by a program.
What's desired is that ansible should create the file, and give it the correct permissions, if it doesn't exist. This is already achieved by the
state=touch
option.However,
touch
has a couple of undesirable side-effects in this use case. Firstly, it does atouch
even when the file does already exist and has the correct perms, which causes spurious updates to the log files last modified & accessed perms. Secondly, ansible registers the step as "changed" every time it's run, even though, as far as I cared, there was nothing that needed to be done. This makes it hard to, eg, drive a correct handler notification from the step.So, a minor enhancement proposal, but a useful one I think.
The text was updated successfully, but these errors were encountered: