Skip to content

Commit

Permalink
fix: [ansible] lineinfile.insertafter, lineinfile.insertbefore, pause…
Browse files Browse the repository at this point in the history
….minutes and package.name (#1776)

* add: test module_lineifile.json

This does not pass the build

* fix: "insertafter" and "insertbefore"

Now also accept all string input

* add: test module_pause.json

This does not pass the build
This is a copy from the example page.

Also add "name": "..." or else it will not pass the build.
This is an other issue that need to be fix

* fix: pause "minutes" and "seconds"

It is now integer and not string as the example

note that the example also accept type "null"

* add: test module_package.json

This does not pass the build

* fix: package "name"

was only accepting string
It now accept both string + array

* empty commit

* add: test module_package.json

issue #509
Ansible schema doesn't handle lists passed to yum module

But it is all ready fix

* fix: module.template.validate must be type "string"

see issue #1256
Ansible template type has an attribute validate which is set to boolean in the JSON schema,
but should be string.

* add: test module_copy.json

issue #1256
Ansible template type has an attribute validate which is set to boolean
in the JSON schema, but should be string.
The copy one has the same validate type and should be checked
and also corrected while working on this.

But there is no "validate" proprety in the module.copy schema.
I do not know how this is posible. This schema ia auto gererated from the
documentation.

Add test module_copy.json to check if any this else is wrong.
The test module_copy.json does not detect this missing property
because there is no "additionalProperties": false for this "properties"
  • Loading branch information
GerryFerdinandus committed Aug 2, 2021
1 parent 1148b3f commit a22542a
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/schemas/json/ansible-role-2.9.json
Expand Up @@ -8567,15 +8567,15 @@
"minProperties": 1
},
"pause": {
"type": "object",
"type": ["object", "null"],
"description": "Pauses playbook execution for a set amount of time, or until a prompt is acknowledged. All parameters are optional. The default behavior is to pause with a prompt.\nTo pause/wait/sleep per host, use the M(wait_for) module.\nYou can use C(ctrl+c) if you wish to advance a pause earlier than it is set to expire or if you need to abort a playbook run entirely. To continue early press C(ctrl+c) and then C(c). To abort a playbook press C(ctrl+c) and then C(a).\nThe pause module integrates into async/parallelized playbooks without any special considerations (see Rolling Updates). When using pauses with the C(serial) playbook parameter (as in rolling updates) you are only prompted once for the current group of hosts.\nThis module is also supported for Windows targets.",
"properties": {
"minutes": {
"type": "string",
"type": "integer",
"description": "A positive number of minutes to pause for."
},
"seconds": {
"type": "string",
"type": "integer",
"description": "A positive number of seconds to pause for."
},
"prompt": {
Expand Down Expand Up @@ -30725,7 +30725,7 @@
"description": "Installs, upgrade and removes packages using the underlying OS package manager.\nFor Windows targets, use the M(win_package) module instead.",
"properties": {
"name": {
"type": "string",
"$ref": "#/definitions/ansible_array",
"description": "Package name, or package specifier with version.\nSyntax varies with package manager. For example C(name-1.0) or C(name=1.0).\nPackage names also vary with package manager; this module will not \"translate\" them per distro. For example C(libyaml-dev), C(libyaml-devel)."
},
"state": {
Expand Down Expand Up @@ -135143,7 +135143,7 @@
"description": "Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file.\nBy default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner.\nThis option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes).\nIMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption."
},
"validate": {
"$ref": "#/definitions/ansible_truth",
"type": "string",
"description": "The validation command to run before copying into place.\nThe path to the file to validate is passed in via '%s' which must be present as in the examples below.\nThe command is passed securely so shell features like expansion and pipes will not work."
},
"variable_end_string": {
Expand Down Expand Up @@ -135742,19 +135742,31 @@
"description": "Used with C(state=present).\nIf set, C(line) can contain backreferences (both positional and named) that will get populated if the C(regexp) matches.\nThis parameter changes the operation of the module slightly; C(insertbefore) and C(insertafter) will be ignored, and if the C(regexp) does not match anywhere in the file, the file will be left unchanged.\nIf the C(regexp) does match, the last matching line will be replaced by the expanded line parameter."
},
"insertafter": {
"type": "string",
"description": "Default: EOF\n\nUsed with C(state=present).\nIf specified, the line will be inserted after the last match of specified regular expression.\nIf the first match is required, use(firstmatch=yes).\nA special value is available; C(EOF) for inserting the line at the end of the file.\nIf specified regular expression has no matches, EOF will be used instead.\nIf C(insertbefore) is set, default value C(EOF) will be ignored.\nIf regular expressions are passed to both C(regexp) and C(insertafter), C(insertafter) is only honored if no match for C(regexp) is found.\nMay not be used with C(backrefs) or C(insertbefore).",
"enum": [
"EOF",
"*regex*"
"anyOf":
[
{
"type": "string",
"enum": [
"EOF",
"*regex*"
]
},
{"type": "string"}
]
},
"insertbefore": {
"type": "string",
"description": "Used with C(state=present).\nIf specified, the line will be inserted before the last match of specified regular expression.\nIf the first match is required, use C(firstmatch=yes).\nA value is available; C(BOF) for inserting the line at the beginning of the file.\nIf specified regular expression has no matches, the line will be inserted at the end of the file.\nIf regular expressions are passed to both C(regexp) and C(insertbefore), C(insertbefore) is only honored if no match for C(regexp) is found.\nMay not be used with C(backrefs) or C(insertafter).",
"enum": [
"BOF",
"*regex*"
"anyOf":
[
{
"type": "string",
"enum": [
"EOF",
"*regex*"
]
},
{"type": "string"}
]
},
"create": {
Expand Down
83 changes: 83 additions & 0 deletions src/test/ansible-role-2.9/module_copy.json
@@ -0,0 +1,83 @@
[
{
"name": "Copy file with owner and permissions",
"copy": {
"src": "/srv/myfiles/foo.conf",
"dest": "/etc/foo.conf",
"owner": "foo",
"group": "foo",
"mode": "0644"
}
},
{
"name": "Copy file with owner and permission, using symbolic representation",
"copy": {
"src": "/srv/myfiles/foo.conf",
"dest": "/etc/foo.conf",
"owner": "foo",
"group": "foo",
"mode": "u=rw,g=r,o=r"
}
},
{
"name": "Another symbolic mode example, adding some permissions and removing others",
"copy": {
"src": "/srv/myfiles/foo.conf",
"dest": "/etc/foo.conf",
"owner": "foo",
"group": "foo",
"mode": "u+rw,g-wx,o-rwx"
}
},
{
"name": "Copy a new \"ntp.conf file into place, backing up the original if it differs from the copied version",
"copy": {
"src": "/mine/ntp.conf",
"dest": "/etc/ntp.conf",
"owner": "root",
"group": "root",
"mode": "0644",
"backup": true
}
},
{
"name": "Copy a new \"sudoers\" file into place, after passing validation with visudo",
"copy": {
"src": "/mine/sudoers",
"dest": "/etc/sudoers",
"validate": "/usr/sbin/visudo -csf %s"
}
},
{
"name": "Copy a \"sudoers\" file on the remote machine for editing",
"copy": {
"src": "/etc/sudoers",
"dest": "/etc/sudoers.edit",
"remote_src": true,
"validate": "/usr/sbin/visudo -csf %s"
}
},
{
"name": "Copy using inline content",
"copy": {
"content": "# This file was moved to /etc/other.conf",
"dest": "/etc/mine.conf"
}
},
{
"name": "If follow=yes, /path/to/file will be overwritten by contents of foo.conf",
"copy": {
"src": "/etc/foo.conf",
"dest": "/path/to/link",
"follow": true
}
},
{
"name": "If follow=no, /path/to/link will become a file and be overwritten by contents of foo.conf",
"copy": {
"src": "/etc/foo.conf",
"dest": "/path/to/link",
"follow": false
}
}
]
74 changes: 74 additions & 0 deletions src/test/ansible-role-2.9/module_lineinfile.json
@@ -0,0 +1,74 @@
[
{
"name": "Ensure SELinux is set to enforcing mode",
"lineinfile": {
"path": "/etc/selinux/config",
"regexp": "^SELINUX=",
"line": "SELINUX=enforcing"
}
},
{
"name": "Make sure group wheel is not in the sudoers configuration",
"lineinfile": {
"path": "/etc/sudoers",
"state": "absent",
"regexp": "^%wheel"
}
},
{
"name": "Replace a localhost entry with our own",
"lineinfile": {
"path": "/etc/hosts",
"regexp": "^127\\.0\\.0\\.1",
"line": "127.0.0.1 localhost",
"owner": "root",
"group": "root",
"mode": "0644"
}
},
{
"name": "Ensure the default Apache port is 8080",
"lineinfile": {
"path": "/etc/httpd/conf/httpd.conf",
"regexp": "^Listen ",
"insertafter": "^#Listen ",
"line": "Listen 8080"
}
},
{
"name": "Ensure we have our own comment added to /etc/services",
"lineinfile": {
"path": "/etc/services",
"regexp": "^# port for http",
"insertbefore": "^www.*80/tcp",
"line": "# port for http by default"
}
},
{
"name": "Add a line to a file if the file does not exist, without passing regexp",
"lineinfile": {
"path": "/tmp/testfile",
"line": "192.168.1.99 foo.lab.net foo",
"create": true
}
},
{
"name": "Ensure the JBoss memory settings are exactly as needed",
"lineinfile": {
"path": "/opt/jboss-as/bin/standalone.conf",
"regexp": "^(.*)Xms(\\\\d+)m(.*)$",
"line": "\\1Xms${xms}m\\3",
"backrefs": true
}
},
{
"name": "Validate the sudoers file before saving",
"lineinfile": {
"path": "/etc/sudoers",
"state": "present",
"regexp": "^%ADMIN ALL=",
"line": "%ADMIN ALL=(ALL) NOPASSWD: ALL",
"validate": "/usr/sbin/visudo -cf %s"
}
}
]
26 changes: 26 additions & 0 deletions src/test/ansible-role-2.9/module_package.json
@@ -0,0 +1,26 @@
[
{
"name": "install ntpdate",
"package": {
"name": "ntpdate",
"state": "present"
}
},
{
"name": "remove the apache package",
"package": {
"name": "{{ apache }}",
"state": "absent"
}
},
{
"name": "install the latest version of Apache and MariaDB",
"package": {
"name": [
"httpd",
"mariadb-server"
],
"state": "latest"
}
}
]
25 changes: 25 additions & 0 deletions src/test/ansible-role-2.9/module_pause.json
@@ -0,0 +1,25 @@
[
{
"name": "a",
"pause": {
"minutes": 5
}
},
{
"name": "b",
"pause": null
},
{
"name": "c",
"pause": {
"prompt": "Make sure org.foo.FooOverload exception is not present"
}
},
{
"name": "d",
"pause": {
"prompt": "Enter a secret",
"echo": false
}
}
]

0 comments on commit a22542a

Please sign in to comment.