I believe this used to work:
config-files:
file:
- managed:
- name: /tmp/file1.conf
- source: salt://files/file1.conf
file:
- managed:
- name: /tmp/file2.conf
- source: salt://files/file2.conf
But now, I only get one file copied over.
Has something changed or am I completely crazy and remembering something wrong?
You can only do one file.managed underneath a single id declaration
On Apr 16, 2013 8:34 AM, "Ben Hosmer" [email protected] wrote:
I believe this used to work:
config-files:
file:
- managed:
- name: /tmp/file1.conf
- source: salt://files/file1.conf
file:
- managed:
- name: /tmp/file2.conf
- source: salt://files/file2.confBut now, I only get one file copied over.
Has something changed or am I completely crazy and remembering something
wrong?—
Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4508
.
I guess I'm crazy then! Thanks for setting me straight.
I tried an ID declaration with a file.managed and a file.exists, and only the file.managed function worked. The documentation is not clear how function declarations under the same ID get processed if they come from the same state.
I'm still uncertain when my function declarations will be silently ignored? Is it when they both come from the same state?
you can't have have two functions from the same state module under the same
ID declaration.
You'll have to split those out under 2 ID declarations.
On Wed, Jul 10, 2013 at 2:37 PM, Mark [email protected] wrote:
I tried an ID declaration with a file.managed and a file.exists, and only
the file.managed function worked. The documentation is not clear how
function declarations under the same ID get processed if they come from the
same state.I'm still uncertain when my function declarations will be silently
ignored? Is it when they both come from the same state?—
Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4508#issuecomment-20771262
.
Dave Boucha | Sr. Engineer
5272 South College Drive, Suite 301 | Murray, UT 84123
_office_ 801-305-3563
[email protected] | www.saltstack.com http://saltstack.com/
No error was thrown because of the multiple declarations of the same state?
Pedro Algarvio @ phone
----- Reply message -----
De: "David Boucha" [email protected]
Para: "saltstack/salt" [email protected]
Assunto: [salt] Manage multiple files in one state declaration. (#4508)
Data: qua, Jul 10, 2013 21:46
you can't have have two functions from the same state module under the same
ID declaration.
You'll have to split those out under 2 ID declarations.
On Wed, Jul 10, 2013 at 2:37 PM, Mark [email protected] wrote:
I tried an ID declaration with a file.managed and a file.exists, and only
the file.managed function worked. The documentation is not clear how
function declarations under the same ID get processed if they come from the
same state.
I'm still uncertain when my function declarations will be silently
ignored? Is it when they both come from the same state?
—
Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4508#issuecomment-20771262
.
Dave Boucha | Sr. Engineer
5272 South College Drive, Suite 301 | Murray, UT 84123
_office_ 801-305-3563
[email protected] | www.saltstack.com http://saltstack.com/
—
Reply to this email directly or view it on GitHub.
The fact that there was no error surprises me. We might want to look into that.
As an aside, file.managed
will verify that a file exists. You don't need both, afaik.
Since it is yaml, you can't have multiple keys with the same name -- I did get a warning (v 0.16.0):
[WARNING ] Duplicate Key: "pkg" found in salt://postgresql environment=base
It would be nice to be able to do something like:
postgresql:
pkg:
- installed
- name: postgresql92-server
pkg:
- installed
- name: postgresql92-contrib
Since we could add a service state ... so the limitation of only one kind of state per id seems to be a limitation of yaml more than of salt? (or not, I tried making the second one pgk.installed, and it complained.)
@rrauenza you can list multiple pkg states like so..
collectd-install:
pkg.installed:
- pkgs:
- collectd-utils
- collectd
For future reference that is documented salt.states.pkg with the following example provided.
mypkgs:
pkg.installed:
- pkgs:
- foo
- bar: 1.2.3-4
- baz
- pkg_verify:
- ignore_types: [config,doc]
But shouldn't it be possible to manage multiple files in one 'file.manage' as the OP was asking:
config-files:
file.managed:
- arg1: value1
- arg2: value2
- arg3: value3
- names:
- /path/to/some/file1:
- source: salt://path/to/source/file1
- /path/to/some/file2:
- source: salt://path/to/source/file2
- /path/to/some/file3:
- source: salt://path/to/source/file3
Do we have any method to use like @shorawitz mentioned?
As @nrsekhar asked is there any method like what @shorawitz mentions? Running into this trying to setup the nginx site files to throw in /etc/nginx/conf.d/ and trying to avoid having to do a full stanza for each file I would need to be there.
Same here, looking for a way to do this to rename multiple files on a target system all in the same state declaration.
For reference, you may want to have a look at file.recurse
to manage a full directory. However, the ability to manage multiple files under a single ID as suggested by @shorawitz would benefit to me aswell
I'd also see a benefit in being able to manage multiple files and their ownership/mode in a single id.
Meanwhile, although a little ugly you can loop over all the files you want to manage.
Simple:
{% for file in
'/etc/ssl/private/' + fqdn + '.key',
'/etc/ssl/private/' + fqdn + '.crt'
%}
{{ file }}:
file.managed:
- source: "salt://application1/{{ file }}"
- user: root
- group: ssl-cert
- mode: 0740
{% endfor %}
Complex:
{% for file in [
{ 'src': '/etc/ssl/private/' + fqdn + '.key', 'dst': '/etc/ssl/private/' + fqdn + '.key', 'group': 'ssl-cert'},
{ 'src': '/etc/ssl/private/' + fqdn + '.crt', 'dst': '/etc/ssl/private/' + fqdn + '.crt', 'group': 'ssl-cert'},
{ 'src': '/etc/nginx/sites-available/application2.conf.j2', 'dst': '/etc/nginx/sites-available/' + fqdn + '.conf', 'group': 'www-data' }
]
%}
{{ file.dst }}:
file.managed:
- source: "salt://application2/{{ file.src }}"
- user: root
- group: "{{ file.group }}"
- mode: 0740
{% endfor %}
Every six months a Google search leads me here then I just get exasperated.
Anyway, Is this still a plan so we don't have to template it out? Or is another renderer more practical or have people just resorted to packaging like rpm/deb/nix/help?
config-files:
file:
- managed:
- name: /tmp/file1.conf
- source: salt://files/file1.conf
file:
- managed:
- name: /tmp/file2.conf
- source: salt://files/file2.conf
I did something like this, it worked. 1 extra line per file.
config-files1:
file.managed:
- name: /tmp/file1.conf
- source: salt://files/file1.conf
config-files2:
file.managed:
- name: /tmp/file2.conf
- source: salt://files/file2.conf
Can someone from the team reopen this issue please?
Meanwhile, although a little ugly you can loop over all the files you want to manage.
Simple:
{% for file in '/etc/ssl/private/' + fqdn + '.key', '/etc/ssl/private/' + fqdn + '.crt' %} {{ file }}: file.managed: - source: "salt://application1/{{ file }}" - user: root - group: ssl-cert - mode: 0740 {% endfor %}
Complex:
{% for file in [ { 'src': '/etc/ssl/private/' + fqdn + '.key', 'dst': '/etc/ssl/private/' + fqdn + '.key', 'group': 'ssl-cert'}, { 'src': '/etc/ssl/private/' + fqdn + '.crt', 'dst': '/etc/ssl/private/' + fqdn + '.crt', 'group': 'ssl-cert'}, { 'src': '/etc/nginx/sites-available/application2.conf.j2', 'dst': '/etc/nginx/sites-available/' + fqdn + '.conf', 'group': 'www-data' } ] %} {{ file.dst }}: file.managed: - source: "salt://application2/{{ file.src }}" - user: root - group: "{{ file.group }}" - mode: 0740 {% endfor %}
State 'copy nginx config file' in SLS 'nginx_install.nginx' is not formed as a list
State 'copy nginx config file' in SLS 'nginx_install.nginx' is not formed as a list
You're probably missing some brackets '[' and ']' to make it a list in the for loop. Show your sls
Most helpful comment
But shouldn't it be possible to manage multiple files in one 'file.manage' as the OP was asking: