(cherry picked from commit ebd8c101fd
)
This commit is contained in:
parent
c4adf62220
commit
7c44c24456
10 changed files with 130 additions and 111 deletions
|
@ -33,8 +33,8 @@ options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Description of a crontab entry or, if env is set, the name of environment variable.
|
- Description of a crontab entry or, if env is set, the name of environment variable.
|
||||||
- Required if C(state=absent).
|
- Required if I(state=absent).
|
||||||
- Note that if name is not set and C(state=present), then a
|
- Note that if name is not set and I(state=present), then a
|
||||||
new crontab entry will always be created, regardless of existing ones.
|
new crontab entry will always be created, regardless of existing ones.
|
||||||
- This parameter will always be required in future releases.
|
- This parameter will always be required in future releases.
|
||||||
type: str
|
type: str
|
||||||
|
@ -47,7 +47,7 @@ options:
|
||||||
description:
|
description:
|
||||||
- The command to execute or, if env is set, the value of environment variable.
|
- The command to execute or, if env is set, the value of environment variable.
|
||||||
- The command should not contain line breaks.
|
- The command should not contain line breaks.
|
||||||
- Required if C(state=present).
|
- Required if I(state=present).
|
||||||
type: str
|
type: str
|
||||||
aliases: [ value ]
|
aliases: [ value ]
|
||||||
state:
|
state:
|
||||||
|
@ -60,10 +60,10 @@ options:
|
||||||
description:
|
description:
|
||||||
- If specified, uses this file instead of an individual user's crontab.
|
- If specified, uses this file instead of an individual user's crontab.
|
||||||
- If this is a relative path, it is interpreted with respect to I(/etc/cron.d).
|
- If this is a relative path, it is interpreted with respect to I(/etc/cron.d).
|
||||||
- If it is absolute, it will typically be I(/etc/crontab).
|
- If it is absolute, it will typically be C(/etc/crontab).
|
||||||
- Many linux distros expect (and some require) the filename portion to consist solely
|
- Many linux distros expect (and some require) the filename portion to consist solely
|
||||||
of upper- and lower-case letters, digits, underscores, and hyphens.
|
of upper- and lower-case letters, digits, underscores, and hyphens.
|
||||||
- To use the C(cron_file) parameter you must specify the C(user) as well.
|
- To use the I(cron_file) parameter you must specify the I(user) as well.
|
||||||
type: str
|
type: str
|
||||||
backup:
|
backup:
|
||||||
description:
|
description:
|
||||||
|
@ -73,34 +73,34 @@ options:
|
||||||
default: no
|
default: no
|
||||||
minute:
|
minute:
|
||||||
description:
|
description:
|
||||||
- Minute when the job should run ( 0-59, *, */2, etc )
|
- Minute when the job should run (C(0-59), C(*), C(*/2), and so on).
|
||||||
type: str
|
type: str
|
||||||
default: "*"
|
default: "*"
|
||||||
hour:
|
hour:
|
||||||
description:
|
description:
|
||||||
- Hour when the job should run ( 0-23, *, */2, etc )
|
- Hour when the job should run (C(0-23), C(*), C(*/2), and so on).
|
||||||
type: str
|
type: str
|
||||||
default: "*"
|
default: "*"
|
||||||
day:
|
day:
|
||||||
description:
|
description:
|
||||||
- Day of the month the job should run ( 1-31, *, */2, etc )
|
- Day of the month the job should run (C(1-31), C(*), C(*/2), and so on).
|
||||||
type: str
|
type: str
|
||||||
default: "*"
|
default: "*"
|
||||||
aliases: [ dom ]
|
aliases: [ dom ]
|
||||||
month:
|
month:
|
||||||
description:
|
description:
|
||||||
- Month of the year the job should run ( 1-12, *, */2, etc )
|
- Month of the year the job should run (C(1-12), C(*), C(*/2), and so on).
|
||||||
type: str
|
type: str
|
||||||
default: "*"
|
default: "*"
|
||||||
weekday:
|
weekday:
|
||||||
description:
|
description:
|
||||||
- Day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
|
- Day of the week that the job should run (C(0-6) for Sunday-Saturday, C(*), and so on).
|
||||||
type: str
|
type: str
|
||||||
default: "*"
|
default: "*"
|
||||||
aliases: [ dow ]
|
aliases: [ dow ]
|
||||||
reboot:
|
reboot:
|
||||||
description:
|
description:
|
||||||
- If the job should be run at reboot. This option is deprecated. Users should use special_time.
|
- If the job should be run at reboot. This option is deprecated. Users should use I(special_time).
|
||||||
version_added: "1.0"
|
version_added: "1.0"
|
||||||
type: bool
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
|
@ -113,7 +113,7 @@ options:
|
||||||
disabled:
|
disabled:
|
||||||
description:
|
description:
|
||||||
- If the job should be disabled (commented out) in the crontab.
|
- If the job should be disabled (commented out) in the crontab.
|
||||||
- Only has effect if C(state=present).
|
- Only has effect if I(state=present).
|
||||||
type: bool
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
|
@ -121,19 +121,19 @@ options:
|
||||||
description:
|
description:
|
||||||
- If set, manages a crontab's environment variable.
|
- If set, manages a crontab's environment variable.
|
||||||
- New variables are added on top of crontab.
|
- New variables are added on top of crontab.
|
||||||
- C(name) and C(value) parameters are the name and the value of environment variable.
|
- I(name) and I(value) parameters are the name and the value of environment variable.
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
insertafter:
|
insertafter:
|
||||||
description:
|
description:
|
||||||
- Used with C(state=present) and C(env).
|
- Used with I(state=present) and I(env).
|
||||||
- If specified, the environment variable will be inserted after the declaration of specified environment variable.
|
- If specified, the environment variable will be inserted after the declaration of specified environment variable.
|
||||||
type: str
|
type: str
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
insertbefore:
|
insertbefore:
|
||||||
description:
|
description:
|
||||||
- Used with C(state=present) and C(env).
|
- Used with I(state=present) and I(env).
|
||||||
- If specified, the environment variable will be inserted before the declaration of specified environment variable.
|
- If specified, the environment variable will be inserted before the declaration of specified environment variable.
|
||||||
type: str
|
type: str
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
|
@ -145,42 +145,44 @@ author:
|
||||||
- Patrick Callahan (@dirtyharrycallahan)
|
- Patrick Callahan (@dirtyharrycallahan)
|
||||||
- Evan Kaufman (@EvanK)
|
- Evan Kaufman (@EvanK)
|
||||||
- Luca Berruti (@lberruti)
|
- Luca Berruti (@lberruti)
|
||||||
|
notes:
|
||||||
|
- Supports C(check_mode).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Ensure a job that runs at 2 and 5 exists. Creates an entry like "0 5,2 * * ls -alh > /dev/null"
|
- name: Ensure a job that runs at 2 and 5 exists. Creates an entry like "0 5,2 * * ls -alh > /dev/null"
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: "check dirs"
|
name: "check dirs"
|
||||||
minute: "0"
|
minute: "0"
|
||||||
hour: "5,2"
|
hour: "5,2"
|
||||||
job: "ls -alh > /dev/null"
|
job: "ls -alh > /dev/null"
|
||||||
|
|
||||||
- name: 'Ensure an old job is no longer present. Removes any job that is prefixed by "#Ansible: an old job" from the crontab'
|
- name: 'Ensure an old job is no longer present. Removes any job that is prefixed by "#Ansible: an old job" from the crontab'
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: "an old job"
|
name: "an old job"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Creates an entry like "@reboot /some/job.sh"
|
- name: Creates an entry like "@reboot /some/job.sh"
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: "a job for reboot"
|
name: "a job for reboot"
|
||||||
special_time: reboot
|
special_time: reboot
|
||||||
job: "/some/job.sh"
|
job: "/some/job.sh"
|
||||||
|
|
||||||
- name: Creates an entry like "PATH=/opt/bin" on top of crontab
|
- name: Creates an entry like "PATH=/opt/bin" on top of crontab
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: PATH
|
name: PATH
|
||||||
env: yes
|
env: yes
|
||||||
job: /opt/bin
|
job: /opt/bin
|
||||||
|
|
||||||
- name: Creates an entry like "APP_HOME=/srv/app" and insert it after PATH declaration
|
- name: Creates an entry like "APP_HOME=/srv/app" and insert it after PATH declaration
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: APP_HOME
|
name: APP_HOME
|
||||||
env: yes
|
env: yes
|
||||||
job: /srv/app
|
job: /srv/app
|
||||||
insertafter: PATH
|
insertafter: PATH
|
||||||
|
|
||||||
- name: Creates a cron file under /etc/cron.d
|
- name: Creates a cron file under /etc/cron.d
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: yum autoupdate
|
name: yum autoupdate
|
||||||
weekday: "2"
|
weekday: "2"
|
||||||
minute: "0"
|
minute: "0"
|
||||||
|
@ -190,18 +192,20 @@ EXAMPLES = r'''
|
||||||
cron_file: ansible_yum-autoupdate
|
cron_file: ansible_yum-autoupdate
|
||||||
|
|
||||||
- name: Removes a cron file from under /etc/cron.d
|
- name: Removes a cron file from under /etc/cron.d
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: "yum autoupdate"
|
name: "yum autoupdate"
|
||||||
cron_file: ansible_yum-autoupdate
|
cron_file: ansible_yum-autoupdate
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Removes "APP_HOME" environment variable from crontab
|
- name: Removes "APP_HOME" environment variable from crontab
|
||||||
cron:
|
ansible.builtin.cron:
|
||||||
name: APP_HOME
|
name: APP_HOME
|
||||||
env: yes
|
env: yes
|
||||||
state: absent
|
state: absent
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''#'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import pwd
|
import pwd
|
||||||
|
|
|
@ -23,6 +23,7 @@ notes:
|
||||||
installed to see questions/settings available.
|
installed to see questions/settings available.
|
||||||
- Some distros will always record tasks involving the setting of passwords as changed. This is due to debconf-get-selections masking passwords.
|
- Some distros will always record tasks involving the setting of passwords as changed. This is due to debconf-get-selections masking passwords.
|
||||||
- It is highly recommended to add I(no_log=True) to task while handling sensitive information using this module.
|
- It is highly recommended to add I(no_log=True) to task while handling sensitive information using this module.
|
||||||
|
- Supports C(check_mode).
|
||||||
requirements:
|
requirements:
|
||||||
- debconf
|
- debconf
|
||||||
- debconf-utils
|
- debconf-utils
|
||||||
|
@ -61,32 +62,32 @@ author:
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Set default locale to fr_FR.UTF-8
|
- name: Set default locale to fr_FR.UTF-8
|
||||||
debconf:
|
ansible.builtin.debconf:
|
||||||
name: locales
|
name: locales
|
||||||
question: locales/default_environment_locale
|
question: locales/default_environment_locale
|
||||||
value: fr_FR.UTF-8
|
value: fr_FR.UTF-8
|
||||||
vtype: select
|
vtype: select
|
||||||
|
|
||||||
- name: Set to generate locales
|
- name: Set to generate locales
|
||||||
debconf:
|
ansible.builtin.debconf:
|
||||||
name: locales
|
name: locales
|
||||||
question: locales/locales_to_be_generated
|
question: locales/locales_to_be_generated
|
||||||
value: en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8
|
value: en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8
|
||||||
vtype: multiselect
|
vtype: multiselect
|
||||||
|
|
||||||
- name: Accept oracle license
|
- name: Accept oracle license
|
||||||
debconf:
|
ansible.builtin.debconf:
|
||||||
name: oracle-java7-installer
|
name: oracle-java7-installer
|
||||||
question: shared/accepted-oracle-license-v1-1
|
question: shared/accepted-oracle-license-v1-1
|
||||||
value: 'true'
|
value: 'true'
|
||||||
vtype: select
|
vtype: select
|
||||||
|
|
||||||
- name: Specifying package you can register/return the list of questions and current values
|
- name: Specifying package you can register/return the list of questions and current values
|
||||||
debconf:
|
ansible.builtin.debconf:
|
||||||
name: tzdata
|
name: tzdata
|
||||||
|
|
||||||
- name: Pre-configure tripwire site passphrase
|
- name: Pre-configure tripwire site passphrase
|
||||||
debconf:
|
ansible.builtin.debconf:
|
||||||
name: tripwire
|
name: tripwire
|
||||||
question: tripwire/site-passphrase
|
question: tripwire/site-passphrase
|
||||||
value: "{{ site_passphrase }}"
|
value: "{{ site_passphrase }}"
|
||||||
|
@ -94,6 +95,8 @@ EXAMPLES = r'''
|
||||||
no_log: True
|
no_log: True
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''#'''
|
||||||
|
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
|
@ -49,29 +49,27 @@ author:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
# Example that prints the loopback address and gateway for each host
|
- name: Print the gateway for each host when defined
|
||||||
- debug:
|
ansible.builtin.debug:
|
||||||
msg: System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}
|
|
||||||
|
|
||||||
- debug:
|
|
||||||
msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}
|
msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}
|
||||||
when: ansible_default_ipv4.gateway is defined
|
when: ansible_default_ipv4.gateway is defined
|
||||||
|
|
||||||
# Example that prints return information from the previous task
|
- name: Get uptime information
|
||||||
- shell: /usr/bin/uptime
|
ansible.builtin.shell: /usr/bin/uptime
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- debug:
|
- name: Print return information from the previous task
|
||||||
|
ansible.builtin.debug:
|
||||||
var: result
|
var: result
|
||||||
verbosity: 2
|
verbosity: 2
|
||||||
|
|
||||||
- name: Display all variables/facts known for a host
|
- name: Display all variables/facts known for a host
|
||||||
debug:
|
ansible.builtin.debug:
|
||||||
var: hostvars[inventory_hostname]
|
var: hostvars[inventory_hostname]
|
||||||
verbosity: 4
|
verbosity: 4
|
||||||
|
|
||||||
# Example that prints two lines of messages, but only if there is an environment value set
|
- name: Prints two lines of messages, but only if there is an environment value set
|
||||||
- debug:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "Provisioning based on YOUR_KEY which is: {{ lookup('env', 'YOUR_KEY') }}"
|
- "Provisioning based on YOUR_KEY which is: {{ lookup('env', 'YOUR_KEY') }}"
|
||||||
- "These servers were built using the password of '{{ password_used }}'. Please retain this for later use."
|
- "These servers were built using the password of '{{ password_used }}'. Please retain this for later use."
|
||||||
|
|
|
@ -71,6 +71,7 @@ notes:
|
||||||
also explicitly set C(fail_on_missing) to C(no) to get the
|
also explicitly set C(fail_on_missing) to C(no) to get the
|
||||||
non-failing behaviour.
|
non-failing behaviour.
|
||||||
- This module is also supported for Windows targets.
|
- This module is also supported for Windows targets.
|
||||||
|
- Supports C(check_mode).
|
||||||
seealso:
|
seealso:
|
||||||
- module: ansible.builtin.copy
|
- module: ansible.builtin.copy
|
||||||
- module: ansible.builtin.slurp
|
- module: ansible.builtin.slurp
|
||||||
|
@ -81,24 +82,24 @@ author:
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Store file into /tmp/fetched/host.example.com/tmp/somefile
|
- name: Store file into /tmp/fetched/host.example.com/tmp/somefile
|
||||||
fetch:
|
ansible.builtin.fetch:
|
||||||
src: /tmp/somefile
|
src: /tmp/somefile
|
||||||
dest: /tmp/fetched
|
dest: /tmp/fetched
|
||||||
|
|
||||||
- name: Specifying a path directly
|
- name: Specifying a path directly
|
||||||
fetch:
|
ansible.builtin.fetch:
|
||||||
src: /tmp/somefile
|
src: /tmp/somefile
|
||||||
dest: /tmp/prefix-{{ inventory_hostname }}
|
dest: /tmp/prefix-{{ inventory_hostname }}
|
||||||
flat: yes
|
flat: yes
|
||||||
|
|
||||||
- name: Specifying a destination path
|
- name: Specifying a destination path
|
||||||
fetch:
|
ansible.builtin.fetch:
|
||||||
src: /tmp/uniquefile
|
src: /tmp/uniquefile
|
||||||
dest: /tmp/special/
|
dest: /tmp/special/
|
||||||
flat: yes
|
flat: yes
|
||||||
|
|
||||||
- name: Storing in a path relative to the playbook
|
- name: Storing in a path relative to the playbook
|
||||||
fetch:
|
ansible.builtin.fetch:
|
||||||
src: /tmp/uniquefile
|
src: /tmp/uniquefile
|
||||||
dest: special/prefix-{{ inventory_hostname }}
|
dest: special/prefix-{{ inventory_hostname }}
|
||||||
flat: yes
|
flat: yes
|
||||||
|
|
|
@ -62,20 +62,21 @@ seealso:
|
||||||
- module: ansible.windows.win_group
|
- module: ansible.windows.win_group
|
||||||
author:
|
author:
|
||||||
- Stephen Fromm (@sfromm)
|
- Stephen Fromm (@sfromm)
|
||||||
|
notes:
|
||||||
|
- Supports C(check_mode).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: Ensure group "somegroup" exists
|
- name: Ensure group "somegroup" exists
|
||||||
group:
|
ansible.builtin.group:
|
||||||
name: somegroup
|
name: somegroup
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Ensure group "docker" exists with correct gid
|
- name: Ensure group "docker" exists with correct gid
|
||||||
group:
|
ansible.builtin.group:
|
||||||
name: docker
|
name: docker
|
||||||
state: present
|
state: present
|
||||||
gid: 1750
|
gid: 1750
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
|
@ -85,17 +86,17 @@ gid:
|
||||||
type: int
|
type: int
|
||||||
sample: 1001
|
sample: 1001
|
||||||
name:
|
name:
|
||||||
description: Group name
|
description: Group name.
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: users
|
sample: users
|
||||||
state:
|
state:
|
||||||
description: Whether the group is present or not
|
description: Whether the group is present or not.
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: 'absent'
|
sample: 'absent'
|
||||||
system:
|
system:
|
||||||
description: Whether the group is a system group or not
|
description: Whether the group is a system group or not.
|
||||||
returned: When C(state) is 'present'
|
returned: When C(state) is 'present'
|
||||||
type: bool
|
type: bool
|
||||||
sample: False
|
sample: False
|
||||||
|
|
|
@ -125,6 +125,7 @@ extends_documentation_fragment:
|
||||||
- validate
|
- validate
|
||||||
notes:
|
notes:
|
||||||
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
|
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
|
||||||
|
- Supports C(check_mode).
|
||||||
seealso:
|
seealso:
|
||||||
- module: ansible.builtin.blockinfile
|
- module: ansible.builtin.blockinfile
|
||||||
- module: ansible.builtin.copy
|
- module: ansible.builtin.copy
|
||||||
|
@ -140,19 +141,19 @@ author:
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
# NOTE: Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
|
# NOTE: Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
|
||||||
- name: Ensure SELinux is set to enforcing mode
|
- name: Ensure SELinux is set to enforcing mode
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/selinux/config
|
path: /etc/selinux/config
|
||||||
regexp: '^SELINUX='
|
regexp: '^SELINUX='
|
||||||
line: SELINUX=enforcing
|
line: SELINUX=enforcing
|
||||||
|
|
||||||
- name: Make sure group wheel is not in the sudoers configuration
|
- name: Make sure group wheel is not in the sudoers configuration
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/sudoers
|
path: /etc/sudoers
|
||||||
state: absent
|
state: absent
|
||||||
regexp: '^%wheel'
|
regexp: '^%wheel'
|
||||||
|
|
||||||
- name: Replace a localhost entry with our own
|
- name: Replace a localhost entry with our own
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/hosts
|
path: /etc/hosts
|
||||||
regexp: '^127\.0\.0\.1'
|
regexp: '^127\.0\.0\.1'
|
||||||
line: 127.0.0.1 localhost
|
line: 127.0.0.1 localhost
|
||||||
|
@ -161,28 +162,28 @@ EXAMPLES = r'''
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
|
||||||
- name: Ensure the default Apache port is 8080
|
- name: Ensure the default Apache port is 8080
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/httpd/conf/httpd.conf
|
path: /etc/httpd/conf/httpd.conf
|
||||||
regexp: '^Listen '
|
regexp: '^Listen '
|
||||||
insertafter: '^#Listen '
|
insertafter: '^#Listen '
|
||||||
line: Listen 8080
|
line: Listen 8080
|
||||||
|
|
||||||
- name: Ensure we have our own comment added to /etc/services
|
- name: Ensure we have our own comment added to /etc/services
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/services
|
path: /etc/services
|
||||||
regexp: '^# port for http'
|
regexp: '^# port for http'
|
||||||
insertbefore: '^www.*80/tcp'
|
insertbefore: '^www.*80/tcp'
|
||||||
line: '# port for http by default'
|
line: '# port for http by default'
|
||||||
|
|
||||||
- name: Add a line to a file if the file does not exist, without passing regexp
|
- name: Add a line to a file if the file does not exist, without passing regexp
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /tmp/testfile
|
path: /tmp/testfile
|
||||||
line: 192.168.1.99 foo.lab.net foo
|
line: 192.168.1.99 foo.lab.net foo
|
||||||
create: yes
|
create: yes
|
||||||
|
|
||||||
# NOTE: Yaml requires escaping backslashes in double quotes but not in single quotes
|
# NOTE: Yaml requires escaping backslashes in double quotes but not in single quotes
|
||||||
- name: Ensure the JBoss memory settings are exactly as needed
|
- name: Ensure the JBoss memory settings are exactly as needed
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /opt/jboss-as/bin/standalone.conf
|
path: /opt/jboss-as/bin/standalone.conf
|
||||||
regexp: '^(.*)Xms(\d+)m(.*)$'
|
regexp: '^(.*)Xms(\d+)m(.*)$'
|
||||||
line: '\1Xms${xms}m\3'
|
line: '\1Xms${xms}m\3'
|
||||||
|
@ -190,7 +191,7 @@ EXAMPLES = r'''
|
||||||
|
|
||||||
# NOTE: Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs.
|
# NOTE: Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs.
|
||||||
- name: Validate the sudoers file before saving
|
- name: Validate the sudoers file before saving
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/sudoers
|
path: /etc/sudoers
|
||||||
state: present
|
state: present
|
||||||
regexp: '^%ADMIN ALL='
|
regexp: '^%ADMIN ALL='
|
||||||
|
@ -199,13 +200,15 @@ EXAMPLES = r'''
|
||||||
|
|
||||||
# See https://docs.python.org/3/library/re.html for further details on syntax
|
# See https://docs.python.org/3/library/re.html for further details on syntax
|
||||||
- name: Use backrefs with alternative group syntax to avoid conflicts with variable values
|
- name: Use backrefs with alternative group syntax to avoid conflicts with variable values
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /tmp/config
|
path: /tmp/config
|
||||||
regexp: ^(host=).*
|
regexp: ^(host=).*
|
||||||
line: \g<1>{{ hostname }}
|
line: \g<1>{{ hostname }}
|
||||||
backrefs: yes
|
backrefs: yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''#'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
|
@ -34,6 +34,8 @@ seealso:
|
||||||
author:
|
author:
|
||||||
- Ansible Core Team
|
- Ansible Core Team
|
||||||
- Michael DeHaan
|
- Michael DeHaan
|
||||||
|
notes:
|
||||||
|
- Supports C(check_mode).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -41,16 +43,16 @@ EXAMPLES = '''
|
||||||
# ansible webservers -m ping
|
# ansible webservers -m ping
|
||||||
|
|
||||||
- name: Example from an Ansible Playbook
|
- name: Example from an Ansible Playbook
|
||||||
ping:
|
ansible.builtin.ping:
|
||||||
|
|
||||||
- name: Induce an exception to see what happens
|
- name: Induce an exception to see what happens
|
||||||
ping:
|
ansible.builtin.ping:
|
||||||
data: crash
|
data: crash
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
ping:
|
ping:
|
||||||
description: value provided with the data parameter
|
description: Value provided with the data parameter.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
sample: pong
|
sample: pong
|
||||||
|
|
|
@ -95,24 +95,25 @@ notes:
|
||||||
previous incorrect behavior, you may be need to adjust your tasks.
|
previous incorrect behavior, you may be need to adjust your tasks.
|
||||||
See U(https://github.com/ansible/ansible/issues/31354) for details.
|
See U(https://github.com/ansible/ansible/issues/31354) for details.
|
||||||
- Option I(follow) has been removed in Ansible 2.5, because this module modifies the contents of the file so I(follow=no) doesn't make sense.
|
- Option I(follow) has been removed in Ansible 2.5, because this module modifies the contents of the file so I(follow=no) doesn't make sense.
|
||||||
|
- Supports C(check_mode).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Before Ansible 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
|
- name: Before Ansible 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/hosts
|
path: /etc/hosts
|
||||||
regexp: '(\s+)old\.host\.name(\s+.*)?$'
|
regexp: '(\s+)old\.host\.name(\s+.*)?$'
|
||||||
replace: '\1new.host.name\2'
|
replace: '\1new.host.name\2'
|
||||||
|
|
||||||
- name: Replace after the expression till the end of the file (requires Ansible >= 2.4)
|
- name: Replace after the expression till the end of the file (requires Ansible >= 2.4)
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/apache2/sites-available/default.conf
|
path: /etc/apache2/sites-available/default.conf
|
||||||
after: 'NameVirtualHost [*]'
|
after: 'NameVirtualHost [*]'
|
||||||
regexp: '^(.+)$'
|
regexp: '^(.+)$'
|
||||||
replace: '# \1'
|
replace: '# \1'
|
||||||
|
|
||||||
- name: Replace before the expression till the begin of the file (requires Ansible >= 2.4)
|
- name: Replace before the expression till the begin of the file (requires Ansible >= 2.4)
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/apache2/sites-available/default.conf
|
path: /etc/apache2/sites-available/default.conf
|
||||||
before: '# live site config'
|
before: '# live site config'
|
||||||
regexp: '^(.+)$'
|
regexp: '^(.+)$'
|
||||||
|
@ -121,7 +122,7 @@ EXAMPLES = r'''
|
||||||
# Prior to Ansible 2.7.10, using before and after in combination did the opposite of what was intended.
|
# Prior to Ansible 2.7.10, using before and after in combination did the opposite of what was intended.
|
||||||
# see https://github.com/ansible/ansible/issues/31354 for details.
|
# see https://github.com/ansible/ansible/issues/31354 for details.
|
||||||
- name: Replace between the expressions (requires Ansible >= 2.4)
|
- name: Replace between the expressions (requires Ansible >= 2.4)
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/hosts
|
path: /etc/hosts
|
||||||
after: '<VirtualHost [*]>'
|
after: '<VirtualHost [*]>'
|
||||||
before: '</VirtualHost>'
|
before: '</VirtualHost>'
|
||||||
|
@ -129,7 +130,7 @@ EXAMPLES = r'''
|
||||||
replace: '# \1'
|
replace: '# \1'
|
||||||
|
|
||||||
- name: Supports common file attributes
|
- name: Supports common file attributes
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /home/jdoe/.ssh/known_hosts
|
path: /home/jdoe/.ssh/known_hosts
|
||||||
regexp: '^old\.host\.name[^\n]*\n'
|
regexp: '^old\.host\.name[^\n]*\n'
|
||||||
owner: jdoe
|
owner: jdoe
|
||||||
|
@ -137,34 +138,36 @@ EXAMPLES = r'''
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
|
||||||
- name: Supports a validate command
|
- name: Supports a validate command
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/apache/ports
|
path: /etc/apache/ports
|
||||||
regexp: '^(NameVirtualHost|Listen)\s+80\s*$'
|
regexp: '^(NameVirtualHost|Listen)\s+80\s*$'
|
||||||
replace: '\1 127.0.0.1:8080'
|
replace: '\1 127.0.0.1:8080'
|
||||||
validate: '/usr/sbin/apache2ctl -f %s -t'
|
validate: '/usr/sbin/apache2ctl -f %s -t'
|
||||||
|
|
||||||
- name: Short form task (in ansible 2+) necessitates backslash-escaped sequences
|
- name: Short form task (in ansible 2+) necessitates backslash-escaped sequences
|
||||||
replace: path=/etc/hosts regexp='\\b(localhost)(\\d*)\\b' replace='\\1\\2.localdomain\\2 \\1\\2'
|
ansible.builtin.replace: path=/etc/hosts regexp='\\b(localhost)(\\d*)\\b' replace='\\1\\2.localdomain\\2 \\1\\2'
|
||||||
|
|
||||||
- name: Long form task does not
|
- name: Long form task does not
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/hosts
|
path: /etc/hosts
|
||||||
regexp: '\b(localhost)(\d*)\b'
|
regexp: '\b(localhost)(\d*)\b'
|
||||||
replace: '\1\2.localdomain\2 \1\2'
|
replace: '\1\2.localdomain\2 \1\2'
|
||||||
|
|
||||||
- name: Explicitly specifying positional matched groups in replacement
|
- name: Explicitly specifying positional matched groups in replacement
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/ssh/sshd_config
|
path: /etc/ssh/sshd_config
|
||||||
regexp: '^(ListenAddress[ ]+)[^\n]+$'
|
regexp: '^(ListenAddress[ ]+)[^\n]+$'
|
||||||
replace: '\g<1>0.0.0.0'
|
replace: '\g<1>0.0.0.0'
|
||||||
|
|
||||||
- name: Explicitly specifying named matched groups
|
- name: Explicitly specifying named matched groups
|
||||||
replace:
|
ansible.builtin.replace:
|
||||||
path: /etc/ssh/sshd_config
|
path: /etc/ssh/sshd_config
|
||||||
regexp: '^(?P<dctv>ListenAddress[ ]+)(?P<host>[^\n]+)$'
|
regexp: '^(?P<dctv>ListenAddress[ ]+)(?P<host>[^\n]+)$'
|
||||||
replace: '#\g<dctv>\g<host>\n\g<dctv>0.0.0.0'
|
replace: '#\g<dctv>\g<host>\n\g<dctv>0.0.0.0'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''#'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
|
@ -47,6 +47,7 @@ notes:
|
||||||
stderr is sent to stdout. If you depend on separated stdout and stderr result keys, please switch to a copy+command set of tasks instead of using script.
|
stderr is sent to stdout. If you depend on separated stdout and stderr result keys, please switch to a copy+command set of tasks instead of using script.
|
||||||
- If the path to the local script contains spaces, it needs to be quoted.
|
- If the path to the local script contains spaces, it needs to be quoted.
|
||||||
- This module is also supported for Windows targets.
|
- This module is also supported for Windows targets.
|
||||||
|
- Does not support C(check_mode).
|
||||||
seealso:
|
seealso:
|
||||||
- module: ansible.builtin.shell
|
- module: ansible.builtin.shell
|
||||||
- module: ansible.windows.win_shell
|
- module: ansible.windows.win_shell
|
||||||
|
@ -59,29 +60,29 @@ extends_documentation_fragment:
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Run a script with arguments (free form)
|
- name: Run a script with arguments (free form)
|
||||||
script: /some/local/script.sh --some-argument 1234
|
ansible.builtin.script: /some/local/script.sh --some-argument 1234
|
||||||
|
|
||||||
- name: Run a script with arguments (using 'cmd' parameter)
|
- name: Run a script with arguments (using 'cmd' parameter)
|
||||||
script:
|
ansible.builtin.script:
|
||||||
cmd: /some/local/script.sh --some-argument 1234
|
cmd: /some/local/script.sh --some-argument 1234
|
||||||
|
|
||||||
- name: Run a script only if file.txt does not exist on the remote node
|
- name: Run a script only if file.txt does not exist on the remote node
|
||||||
script: /some/local/create_file.sh --some-argument 1234
|
ansible.builtin.script: /some/local/create_file.sh --some-argument 1234
|
||||||
args:
|
args:
|
||||||
creates: /the/created/file.txt
|
creates: /the/created/file.txt
|
||||||
|
|
||||||
- name: Run a script only if file.txt exists on the remote node
|
- name: Run a script only if file.txt exists on the remote node
|
||||||
script: /some/local/remove_file.sh --some-argument 1234
|
ansible.builtin.script: /some/local/remove_file.sh --some-argument 1234
|
||||||
args:
|
args:
|
||||||
removes: /the/removed/file.txt
|
removes: /the/removed/file.txt
|
||||||
|
|
||||||
- name: Run a script using an executable in a non-system path
|
- name: Run a script using an executable in a non-system path
|
||||||
script: /some/local/script
|
ansible.builtin.script: /some/local/script
|
||||||
args:
|
args:
|
||||||
executable: /some/remote/executable
|
executable: /some/remote/executable
|
||||||
|
|
||||||
- name: Run a script using an executable in a system path
|
- name: Run a script using an executable in a system path
|
||||||
script: /some/local/script.py
|
ansible.builtin.script: /some/local/script.py
|
||||||
args:
|
args:
|
||||||
executable: python3
|
executable: python3
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -79,6 +79,7 @@ options:
|
||||||
version_added: 2.2
|
version_added: 2.2
|
||||||
notes:
|
notes:
|
||||||
- For AIX, group subsystem names can be used.
|
- For AIX, group subsystem names can be used.
|
||||||
|
- Supports C(check_mode).
|
||||||
seealso:
|
seealso:
|
||||||
- module: ansible.windows.win_service
|
- module: ansible.windows.win_service
|
||||||
author:
|
author:
|
||||||
|
@ -88,43 +89,45 @@ author:
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Start service httpd, if not started
|
- name: Start service httpd, if not started
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: httpd
|
name: httpd
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Stop service httpd, if started
|
- name: Stop service httpd, if started
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: httpd
|
name: httpd
|
||||||
state: stopped
|
state: stopped
|
||||||
|
|
||||||
- name: Restart service httpd, in all cases
|
- name: Restart service httpd, in all cases
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: httpd
|
name: httpd
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
- name: Reload service httpd, in all cases
|
- name: Reload service httpd, in all cases
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: httpd
|
name: httpd
|
||||||
state: reloaded
|
state: reloaded
|
||||||
|
|
||||||
- name: Enable service httpd, and not touch the state
|
- name: Enable service httpd, and not touch the state
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: httpd
|
name: httpd
|
||||||
enabled: yes
|
enabled: yes
|
||||||
|
|
||||||
- name: Start service foo, based on running process /usr/bin/foo
|
- name: Start service foo, based on running process /usr/bin/foo
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: foo
|
name: foo
|
||||||
pattern: /usr/bin/foo
|
pattern: /usr/bin/foo
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Restart network service for interface eth0
|
- name: Restart network service for interface eth0
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: network
|
name: network
|
||||||
state: restarted
|
state: restarted
|
||||||
args: eth0
|
args: eth0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''#'''
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
Loading…
Reference in a new issue