Class: Ansible::Ruby::Modules::Lineinfile
- Inherits:
-
Base
- Object
- Ansible::Ruby::Models::Base
- Base
- Ansible::Ruby::Modules::Lineinfile
- Includes:
- Helpers::FileAttributes
- Defined in:
- lib/ansible/ruby/modules/generated/files/lineinfile.rb,
lib/ansible/ruby/modules/custom/files/lineinfile.rb
Overview
This module ensures a particular line is in a file, or replace an existing line using a back-referenced regular expression. This is primarily useful when you want to change a single line in a file only. See the M(replace) module if you want to change multiple, similar lines or check M(blockinfile) if you want to insert/update/remove a block of lines in a file. For other cases, see the M(copy) or M(template) modules.
Instance Method Summary collapse
-
#backrefs ⇒ :yes, ...
Used with C(state=present).
-
#backup ⇒ :yes, ...
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
-
#create ⇒ :yes, ...
Used with C(state=present).
-
#firstmatch ⇒ :yes, ...
Used with C(insertafter) or C(insertbefore).
-
#insertafter ⇒ :EOF, ...
Used with C(state=present).
-
#insertbefore ⇒ :BOF, ...
Used with C(state=present).
-
#line ⇒ String?
Required for C(state=present).
-
#others ⇒ Object?
All arguments accepted by the M(file) module also work here.
-
#path ⇒ String
The file to modify.,Before 2.3 this option was only usable as I(dest), I(destfile) and I(name).
-
#regexp ⇒ String?
The regular expression to look for in every line of the file.
-
#state ⇒ :absent, ...
Whether the line should be there or not.
Methods included from Helpers::FileAttributes
Methods inherited from Base
Methods inherited from Ansible::Ruby::Models::Base
attr_option, attr_options, attribute, fix_inclusion, #initialize, remove_existing_validations, #to_h, validates
Constructor Details
This class inherits a constructor from Ansible::Ruby::Models::Base
Instance Method Details
#backrefs ⇒ :yes, ...
Returns Used with C(state=present). If set, C(line) can contain backreferences (both positional and named) that will get populated if the C(regexp) matches. This flag changes the operation of the module slightly; C(insertbefore) and C(insertafter) will be ignored, and if the C(regexp) doesn’t match anywhere in the file, the file will be left unchanged. If the C(regexp) does match, the last matching line will be replaced by the expanded line parameter.
29 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 29 attribute :backrefs |
#backup ⇒ :yes, ...
Returns Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
45 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 45 attribute :backup |
#create ⇒ :yes, ...
Returns Used with C(state=present). If specified, the file will be created if it does not already exist. By default it will fail if the file is missing.
41 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 41 attribute :create |
#firstmatch ⇒ :yes, ...
Returns Used with C(insertafter) or C(insertbefore). If set, C(insertafter) and C(inserbefore) find a first line has regular expression matches.
49 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 49 attribute :firstmatch |
#insertafter ⇒ :EOF, ...
Returns Used with C(state=present). If specified, the line will be inserted after the last match of specified regular expression. If the first match is required, use(firstmatch=yes). A special value is available; C(EOF) for inserting the line at the end of the file. If specified regular expression has no matches, EOF will be used instead. If regular expressions are passed to both C(regexp) and C(insertafter), C(insertafter) is only honored if no match for C(regexp) is found. May not be used with C(backrefs).
33 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 33 attribute :insertafter |
#insertbefore ⇒ :BOF, ...
Returns Used with C(state=present). If specified, the line will be inserted before the last match of specified regular expression. If the first match is required, use(firstmatch=yes). A value is available; C(BOF) for inserting the line at the beginning of the file. If specified regular expression has no matches, the line will be inserted at the end of the file. If regular expressions are passed to both C(regexp) and C(insertbefore), C(insertbefore) is only honored if no match for C(regexp) is found. May not be used with C(backrefs).
37 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 37 attribute :insertbefore |
#line ⇒ String?
Returns Required for C(state=present). The line to insert/replace into the file. If C(backrefs) is set, may contain backreferences that will get expanded with the C(regexp) capture groups if the regexp matches.
25 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 25 attribute :line |
#others ⇒ Object?
Returns All arguments accepted by the M(file) module also work here.
53 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 53 attribute :others |
#path ⇒ String
Returns The file to modify.,Before 2.3 this option was only usable as I(dest), I(destfile) and I(name).
13 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 13 attribute :path |
#regexp ⇒ String?
Returns The regular expression to look for in every line of the file. For C(state=present), the pattern to replace if found. Only the last line found will be replaced. For C(state=absent), the pattern of the line(s) to remove. Uses Python regular expressions. See U(docs.python.org/2/library/re.html).
17 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 17 attribute :regexp |
#state ⇒ :absent, ...
Returns Whether the line should be there or not.
21 |
# File 'lib/ansible/ruby/modules/generated/files/lineinfile.rb', line 21 attribute :state |