Skip to content

Instantly share code, notes, and snippets.

Avatar

Olivier Clavel zeitounator

View GitHub Profile
View session.txt
$ cat test.yml
---
- hosts: localhost
gather_facts: false
vars:
my_user_name: toto
my_password: with$sign
tasks:
View No-reproduce-session.txt
$ docker --version
Docker version 20.10.8, build 3967b7d
$ docker-compose --version
docker-compose version 1.29.2, build unknown
$ tree -a
.
├── config
│   ├── .env.dev
View gist:c55f0acbfafc493b27c2506aae943a83
:/tmp$ git clone git@github.com:sathishsoundharajan/ansible-repro.git
Cloning into 'ansible-repro'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 17 (delta 1), reused 16 (delta 0), pack-reused 0
Receiving objects: 100% (17/17), done.
Resolving deltas: 100% (1/1), done.
:/tmp$ cd ansible-repro/
✔ /tmp/ansible-repro [main {origin/main}|✔]
View Delegationdemo.sh
# Just to show you this does work, here is a demo using docker.
# If you don't care about how the example is set up, you can directly jump to line 111
# First the demo overall directory structure
$ tree -a
.
├── delegation_demo.yml
└── inventory
├── .docker-compose
View gist:6aa3b57c872c59103bc36bb1fc2487a9
# All equivalent (on exaustive list)
roles:
- { role: OTP_WEB, ENV: "{{ENV}}", ACTION: "{{ACTION}}", when: "ENV == 'dev' and 'OTP' in instance_name" }
- { role: OTP_WEB, ENV: "{{ENV}}", ACTION: "{{ACTION}}", when: 'ENV == "dev" and "OTP" in instance_name' }
- { role: OTP_WEB, ENV: "{{ENV}}", ACTION: "{{ACTION}}", when: 'ENV == ''dev'' and ''OTP'' in instance_name' }
- { role: OTP_WEB, ENV: "{{ENV}}", ACTION: "{{ACTION}}", when: "ENV == \"dev\" and \"OTP\" in instance_name" }
View gist:4ae161aacb03f988f3c086dab80ce1d3
# Port 8080 is already taken on my machine so I use a free one => 9999
$ docker run -d --rm --name testnginx -p 9999:80 nginx
c48960b23446714447471f1f1948f2eb3954e0b820ae34b4559ad5ab17bfc3ca
# At this point the container is up and running
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d6a688f6675 nginx "/docker-entrypoint.…" 13 seconds ago Up 12 seconds 0.0.0.0:9999->80/tcp, :::9999->80/tcp testnginx
# Now let's call the mapped port on localhost and get the default nginx page
View gist:2e88fa8e87119050c9d9e455dbaa4b53
$ ansible localhost -m debug -a "msg={{ multi_config | type_debug }}" -e '{"multi_config":{"aa":111,"bb":222,"cc":444}}'
localhost | SUCCESS => {
"msg": "dict"
}
$ ansible localhost -m debug -a var=multi_config -e '{"multi_config":{"aa":111,"bb":222,"cc":444}}'
localhost | SUCCESS => {
"multi_config": {
"aa": 111,
"bb": 222,
View gist:28ca735058eed16891b6d96989a09379
#### 1 - var is a dict inside the playbook #####
$ cat test.yml
- hosts: localhost
gather_facts: false
vars:
impactedEntities: {"type":"HOST","name":"xxxxxxxx.xxxx.xxxxxx.xx","entity":"HOST-053BD6D9938F01C5"}
tasks:
View iosxr_ntp.yml
---
vars:
ntp_peers:
address: "{{ item.address }}"
reachability: "{{ item.reachability}}"
keys:
result:
value: "{{ ntp_peers }}"
top: '{http://cisco.com/ns/yang/Cisco-IOS-XR-ip-ntp-oper}ntp/{http://cisco.com/ns/yang/Cisco-IOS-XR-ip-ntp-oper}nodes/{http://cisco.com/ns/yang/Cisco-IOS-XR-ip-ntp-oper}node/{http://cisco.com/ns/yang/Cisco-IOS-XR-ip-ntp-oper}associations/{http://cisco.com/ns/yang/Cisco-IOS-XR-ip-ntp-oper}peer-summary-info/{http://cisco.com/ns/yang/Cisco-IOS-XR-ip-ntp-oper}peer-info-common'
items:
View 0-playbook.yml
- hosts: localhost
gather_facts: false
vars:
"nodes": {
"node1": {
"last_shutdown": "date",
"level": {
"kind_node": { }
},