Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2016 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/66e5a718523e7b56774c0d4d6abc4419 to your computer and use it in GitHub Desktop.
Save anonymous/66e5a718523e7b56774c0d4d6abc4419 to your computer and use it in GitHub Desktop.
# Client Alive Interval
clientaliveinterval:
file.line:
- name: /etc/ssh/sshd_config
- content: 'ClientAliveInterval 900'
- match: '^#ClientAliveInterval'
- mode: ensure
# Client Alive Count Max
clientalivecountmax:
file.line:
- name: /etc/ssh/sshd_config
- content: 'ClientAliveCountMax 0'
- match: '^#ClientAliveCountMax'
- mode: ensure
----------
ID: clientaliveinterval
Function: file.line
Name: /etc/ssh/sshd_config
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1733, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1652, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/states/file.py", line 2724, in line
backup=backup, quiet=quiet, indent=indent)
File "/usr/lib/python2.7/site-packages/salt/modules/file.py", line 1627, in line
raise CommandExecutionError("Wrong conditions? "
CommandExecutionError: Wrong conditions? Unable to ensure line without knowing where to put it before and/or after.
Started: 19:02:47.358671
Duration: 9.581 ms
Changes:
----------
ID: clientalivecountmax
Function: file.line
Name: /etc/ssh/sshd_config
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1733, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1652, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/states/file.py", line 2724, in line
backup=backup, quiet=quiet, indent=indent)
File "/usr/lib/python2.7/site-packages/salt/modules/file.py", line 1627, in line
raise CommandExecutionError("Wrong conditions? "
CommandExecutionError: Wrong conditions? Unable to ensure line without knowing where to put it before and/or after.
Started: 19:02:47.368427
Duration: 0.817 ms
Changes:
@wolfpackmars2
Copy link

wolfpackmars2 commented Nov 26, 2016

It's saying that if you use ensure, you need to specify a location to insert the line if it doesn't exist.

Try adding:

- location: end

To your states file. If the line doesn't already exist, it will append the line to the end of the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment