copy a file from ansible source to server:
- name: copy config file
copy:
src: "filename.ext"
dest: "/file/destination/"
mode: 0600
template a file to remote server (replace variables in the file on the fly):
- name: template config
template:
src: "filename.ext.j2"
dest: "/file/destination/"
mode: 0644
Download file from the internet:
- name: Download package
ansible.builtin.get_url:
url: https://url.to.the.you.need
dest: /file/destination/
mode: '0755'
install local installation package
- name: Install .deb package
apt:
deb: /file/source/filename.deb
install apt packages:
- name: install package
apt:
name: "package name"
run docker container:
- name: Run container
docker_container:
name: container-name
image: container-image
state: started (optional)
restart_policy: always (optional)
recreate: yes (optional)
env:
variable_name: "variable_value"
ports:
- "host_port:container_port"
volumes:
- "host_path:container_path"
create group:
- name: Create group
ansible.builtin.group:
name: group name
gid: 1000 (optional)
create user:
- name: Create user
ansible.builtin.user:
name: user_name
group: user_group
comment: user (optional)
uid: 1000
(optional)
create directory:
- name: Prepare directory
file:
group: group_name
owner: user_name
mode: 0700
state: directory
path: "folder_name"
run command on shell:
- name: run command
ansible.builtin.command: path/to/binary (command parameter)
to use a handler you need to notify it when needed:
notify: restart kibana
this will run the handler after all the tasks have been completed so if more than one task triggers the handler it will only restart the service once
restart a service:
- name: restart kibana
service: name=kibana state=restarted
reload systemd files:
- name: Reload systemd files
ansible.builtin.systemd:
daemon_reload: yes
change line in file:
this example replaces the line that starts with "ExecStart=" in /etc/kibana/kibana.yml
- name: remove logging directive from startup parameters
ansible.builtin.lineinfile:
path: /etc/kibana/kibana.yml
regexp: '^ExecStart='
line: ExecStart=/usr/share/kibana/bin/kibana --pid.file="/run/kibana/kibana.pid"