-
-
Save nicksan2c/4b9f2374596f1f21cfb358a692146fac to your computer and use it in GitHub Desktop.
ansible quick tips for some modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check existing | |
- name: Ansible check file exists. | |
stat: | |
path: /etc/filename | |
register: file_status | |
- debug: | |
msg: "File exists..." | |
when: file_status.stat.exists | |
- debug: | |
msg: "File not found" | |
when: not file_status.stat.exists | |
- name: check phantomjs executable is present | |
shell: "which phantomjs" | |
register: result | |
ignore_errors: true | |
- fail: | |
msg: "PhantomJS is not found! You need to install it first." | |
when: result.rc != 0 | |
# Set owner for the directory recursively | |
- file: | |
path: "/path/to/directory" | |
owner: "{{ ansible_user }}" | |
group: "{{ ansible_user }}" | |
recurse: true | |
become: true | |
# Trigger handlers always | |
- name: restart app with supervisor | |
command: "/bin/true" | |
notify: | |
- restart app | |
- debug: msg="trigger nginx-restart" | |
notify: nginx-restart | |
changed_when: true | |
# Check command output to match | |
- name: Check which python version is installed | |
shell: "python3 --version" | |
register: python_output | |
ignore_errors: true | |
- debug: | |
var: python_output | |
when: python_output.stdout != "Python {{ python_version }}" | |
# Define variable | |
- set_fact: | |
one_fact: something | |
other_fact: "{{ local_var * 2 }}" | |
another_fact: "{{ some_registered_var.results | map(attribute='ansible_facts.some_fact') | list }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment