Skip to content

Instantly share code, notes, and snippets.

View zeitounator's full-sized avatar

Olivier Clavel zeitounator

View GitHub Profile
$ cat inventory.yml
all:
children:
# empty
python:
hosts:
test-python-app-01:
gitlab:
hosts:
$ tree
.
├── replace.yml
└── test.txt
0 directories, 2 files
$ cat test.txt
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
$ tree
.
├── playbook.yml
└── roles
└── test
├── defaults
│   └── main.yml
└── tasks
└── main.yml
$ cat inventory.yml
---
my_group:
hosts:
server1:
ansible_host: www.server1.com
server2:
vars:
var1: 100.100.1.1
var2: abc
$ tree
.
├── inventories
│   └── test
│   └── hosts.yml
├── playbook.yml
├── vars.yml
└── vault.yml
2 directories, 4 files
---
- hosts: localhost
become: false
gather_facts: false
vars:
example_list: [{"key1":"value_of_first_key"},{"key2":"value_of_second_key"}]
tasks:
- name: print user records
---
- block:
- name: Execute wsadmin
ansible.builtin.command: "script.sh {{ argument }}"
register: result
failed_when: result.stdout is search('This resulted in error')
rescue:
- name: Status
ansible.builtin.debug:
msg: "WARNING: THERE IS AN ERROR!!!"
$ cat group_vars/your_group.yml
images:
- nginx
- ubuntu
$ cat playbook.yml
- name: pull images
hosts: your_group
tasks:
- name: Debug my vars
vars:
var1: {{ result.meta.appname }}
var2: {{ result.meta.vipport }}
ansible.buitin.debug:
msg:
- "{{ var1 }}"
- "{{ var2 }}"
$ ansible --version
ansible [core 2.14.1]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /tmp/test/.venv/lib/python3.10/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /tmp/test/.venv/bin/ansible
python version = 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] (/tmp/test/.venv/bin/python3.10)
jinja version = 3.1.2
libyaml = True