Ansible: Difference between revisions
From Halfface
Jump to navigationJump to search
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
=what does it mean= | |||
<pre> | |||
ansible-galaxy Perform various Role and Collection related operations. | |||
</pre> | |||
=ansible-confg/ansible.cfg= | |||
Configure ansible | |||
ansible-config init | |||
=ansible-doc= | |||
List available plugins | |||
ansible-doc -l | |||
Man page of plugin | |||
ansible-doc community.crypto.openssh_keypair | |||
=ansible options= | =ansible options= | ||
-l SUBSET, --limit SUBSET (further limit selected hosts to an additional pattern) | -l SUBSET, --limit SUBSET (further limit selected hosts to an additional pattern) | ||
| Line 51: | Line 64: | ||
.vault_pass | .vault_pass | ||
=Specify vault password file= | =Specify vault password file= | ||
ansible-vault encrypt --vault-password-file .vault_pass < | ansible-vault encrypt --vault-password-file .vault_pass <file> | ||
ansible-vault decrypt --vault-password-file .vault_pass <file> | |||
=leave/exit/deactivate a Python virtualenv= | |||
deactivate | deactivate | ||
=get errors without \n. Readable= | |||
ANSIBLE_STDOUT_CALLBACK=yaml ansible ... | |||
=roles= | |||
=redis.yml= | |||
--- | |||
- name: Apply Redis role and system tuning | |||
hosts: redis | |||
become: true | |||
roles: | |||
- role: redis | |||
files | |||
roles/redis/defaults/main.yml | |||
roles/redis/handlers/main.yml | |||
roles/redis/tasks/main.yml | |||
roles/redis/templates/redis.conf.j2 | |||
=ansible localhost= | |||
[WARNING]: No inventory was parsed, only implicit localhost is available | |||
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' | |||
ansible-playbook *.yml -i localhost, -c local | |||
Latest revision as of 14:03, 5 January 2026
what does it mean
ansible-galaxy Perform various Role and Collection related operations.
ansible-confg/ansible.cfg
Configure ansible
ansible-config init
ansible-doc
List available plugins
ansible-doc -l
Man page of plugin
ansible-doc community.crypto.openssh_keypair
ansible options
-l SUBSET, --limit SUBSET (further limit selected hosts to an additional pattern) -t TAGS, --tags TAGS (only run plays and tasks tagged with these values) -e EXTRA_VARS, --extra-vars EXTRA_VARS (set additional variables as key=value or YAML/JSON, if filename prepend with @)
dont fail on errors
ignore_errors: yes
Start where you left off
ansible-playbook playbook.yml --start-at-task="install packages"
adhoc command
ansible remote.host -u ${USER}_sysadmin -a id
debug
- name: debug1
debug:
var: filesystem
- name: debug2
debug:
msg: "Template:Item.mount"
loop: "Template:Ansible mounts"
Print a register
- name: Print return information from the previous task
debug:
msg: "Template:Vm data"
date
Test to get dates with wanted format. test.yml # ansible-playbook test.yml
- hosts: localhost
vars:
# date_hour_minute: "{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}"
date_hour_minute: "{{ lookup('pipe','date +%Y-%m-%d_%H-%M-%S') }}"
tasks:
- debug: msg="the current date is {{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}"
- debug: msg="{{ date_hour_minute }}"
disable fact caching
export ANSIBLE_GATHERING=implicit
variable in jinja2
{{ variable }}
get ansible variables
ansible -b -u ${USER}_sysadmin --extra-vars "ansible_sudo_pass=${COMPANY_PASSWORD}" klara-ikeaapp01 -m ansible.builtin.setup
ansible -m debug -a var=hostvars[inventory_hostname] all
disable logging
ANSIBLE_LOG_PATH=" " ansible-playbook...
ansible-vault
ansible-vault decrypt kubeadmin-password
Looks for
.vault_pass
Specify vault password file
ansible-vault encrypt --vault-password-file .vault_pass <file> ansible-vault decrypt --vault-password-file .vault_pass <file>
leave/exit/deactivate a Python virtualenv
deactivate
get errors without \n. Readable
ANSIBLE_STDOUT_CALLBACK=yaml ansible ...
roles
redis.yml
---
- name: Apply Redis role and system tuning
hosts: redis
become: true
roles:
- role: redis
files
roles/redis/defaults/main.yml roles/redis/handlers/main.yml roles/redis/tasks/main.yml roles/redis/templates/redis.conf.j2
ansible localhost
[WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' ansible-playbook *.yml -i localhost, -c local