How to print specific content over a loop in Ansible - networking

I'm a bit stuck with Ansible trying to print some variables from a return of F5.
I'm trying to print which nodes are configured in a determinated pool. I can get all the result:
TASK [f5_getpoolmembers : Ver IPs de un pool] ***********************************************************************************
ok: [localhost] => (item=[u'pool_createdby_ansible_f5']) =>
msg:
- pool_createdby_ansible_f5
- - address: 10.10.10.34
connection_limit: 0
description: prova_ansible_pool
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'yes'
full_path: /Common/10.10.10.34:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.10.10.34:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
- address: 10.100.250.5
connection_limit: 0
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'no'
full_path: /Common/10.100.250.5:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.100.250.5:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
with that code:
- name: "Ver IPs de un pool"
debug:
msg:
- "{{item.name}}"
- "{{item.members}}"
loop: "{{pool_facts.ltm_pools}}"
loop_control:
label:
- "{{item.name}}"
when: item.name is search "ansible"
The problem is when I try to print only the name for every node in the pool. I can't find the way to do it. Tried many options like nested or subelements, but didn't work. If i try to print only the name, I just get the first node:
TASK [f5_getpoolmembers : Ver IPs de un pool] ***********************************************************************************
ok: [localhost] => (item=[u'pool_createdby_ansible_f5']) =>
msg:
- pool_createdby_ansible_f5
- 10.10.10.34:80
Doing this:
- name: "Ver IPs de un pool"
debug:
msg:
- "{{item.name}}"
- "{{item.members[0].name}}"
I know that it's wrong, so that's why I'm here to get some advices.
Edit: Added the complete structure of the pool:
ltm_pools:
- active_member_count: 0
all_avg_queue_entry_age: 0
all_max_queue_entry_age_ever: 0
all_max_queue_entry_age_recently: 0
all_num_connections_queued_now: 0
all_num_connections_serviced: 0
all_queue_head_entry_age: 0
allow_nat: 'yes'
allow_snat: 'yes'
availability_status: unknown
available_member_count: 3
client_ip_tos: pass-through
client_link_qos: pass-through
current_sessions: 0
enabled_status: enabled
full_path: /Common/pool_createdby_ansible_f5
ignore_persisted_weight: 'no'
lb_method: ratio-member
member_count: 3
members:
- address: 10.10.10.34
connection_limit: 0
description: prova_ansible_pool
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'yes'
full_path: /Common/10.10.10.34:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.10.10.34:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
- address: 10.100.250.5
connection_limit: 0
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'no'
full_path: /Common/10.100.250.5:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.100.250.5:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
- address: 10.55.55.4
connection_limit: 0
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'no'
full_path: /Common/10.55.55.4:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.55.55.4:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
minimum_active_members: 0
minimum_up_members: 0
minimum_up_members_action: failover
minimum_up_members_checking: 'no'
name: pool_createdby_ansible_f5
pool_avg_queue_entry_age: 0
pool_max_queue_entry_age_ever: 0
pool_max_queue_entry_age_recently: 0
pool_num_connections_queued_now: 0
pool_num_connections_serviced: 0
pool_queue_head_entry_age: 0
priority_group_activation: 0
queue_depth_limit: 0
queue_on_connection_limit: 'no'
queue_time_limit: 0
reselect_tries: 0
server_ip_tos: pass-through
server_link_qos: pass-through
server_side_bits_in: 0
server_side_bits_out: 0
server_side_current_connections: 0
server_side_max_connections: 0
server_side_pkts_in: 0
server_side_pkts_out: 0
server_side_total_connections: 0
service_down_action: none
slow_ramp_time: 10
status_reason: The children pool member(s) either don't have service checking enabled, or service check results are not available yet
total_requests: 0

You will have to use subelements, indeed.
When you are using the subelements('dictionary_key') filter, then you end up with:
item.0: an item from the list of your loop
item.1: an item from the nested list inside dictionary_key of each item.0 item
Given the playbook:
- hosts: all
gather_facts: no
tasks:
- debug:
msg:
- "{{ item.0.name }}"
- "{{ item.1.name }}"
loop_control:
label:
- "{{ item.0.name }}"
loop: "{{ pools_facts.ltm_pools | subelements('members') }}"
when: "'ansible' in item.0.name"
vars:
pools_facts:
ltm_pools:
- active_member_count: 0
all_avg_queue_entry_age: 0
all_max_queue_entry_age_ever: 0
all_max_queue_entry_age_recently: 0
all_num_connections_queued_now: 0
all_num_connections_serviced: 0
all_queue_head_entry_age: 0
allow_nat: 'yes'
allow_snat: 'yes'
availability_status: unknown
available_member_count: 3
client_ip_tos: pass-through
client_link_qos: pass-through
current_sessions: 0
enabled_status: enabled
full_path: /Common/pool_createdby_ansible_f5
ignore_persisted_weight: 'no'
lb_method: ratio-member
member_count: 3
members:
- address: 10.10.10.34
connection_limit: 0
description: prova_ansible_pool
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'yes'
full_path: /Common/10.10.10.34:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.10.10.34:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
- address: 10.100.250.5
connection_limit: 0
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'no'
full_path: /Common/10.100.250.5:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.100.250.5:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
- address: 10.55.55.4
connection_limit: 0
dynamic_ratio: 1
ephemeral: 'no'
fqdn_autopopulate: 'no'
full_path: /Common/10.55.55.4:80
inherit_profile: 'yes'
logging: 'no'
monitors: []
name: 10.55.55.4:80
partition: Common
priority_group: 0
rate_limit: 'no'
ratio: 1
real_session: user-enabled
real_state: unchecked
state: present
minimum_active_members: 0
minimum_up_members: 0
minimum_up_members_action: failover
minimum_up_members_checking: 'no'
name: pool_createdby_ansible_f5
pool_avg_queue_entry_age: 0
pool_max_queue_entry_age_ever: 0
pool_max_queue_entry_age_recently: 0
pool_num_connections_queued_now: 0
pool_num_connections_serviced: 0
pool_queue_head_entry_age: 0
priority_group_activation: 0
queue_depth_limit: 0
queue_on_connection_limit: 'no'
queue_time_limit: 0
reselect_tries: 0
server_ip_tos: pass-through
server_link_qos: pass-through
server_side_bits_in: 0
server_side_bits_out: 0
server_side_current_connections: 0
server_side_max_connections: 0
server_side_pkts_in: 0
server_side_pkts_out: 0
server_side_total_connections: 0
service_down_action: none
slow_ramp_time: 10
status_reason: The children pool member(s) either don't have service checking enabled, or service check results are not available yet
total_requests: 0
This gives the output:
PLAY [all] *********************************************************************************************************
TASK [debug] *******************************************************************************************************
ok: [localhost] => (item=['pool_createdby_ansible_f5']) => {
"msg": [
"pool_createdby_ansible_f5",
"10.10.10.34:80"
]
}
ok: [localhost] => (item=['pool_createdby_ansible_f5']) => {
"msg": [
"pool_createdby_ansible_f5",
"10.100.250.5:80"
]
}
ok: [localhost] => (item=['pool_createdby_ansible_f5']) => {
"msg": [
"pool_createdby_ansible_f5",
"10.55.55.4:80"
]
}
PLAY RECAP *********************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

I have built a successful playbook. I chose to list more options than names of the members though. You could modify this to spit out just their names. As a note my playbokk has the variable poolName for a survey. Here is my playbook:
- hosts: localhost
tasks:
- name: collect device info
bigip_device_info:
gather_subset:
- ltm-pools
delegate_to: localhost
register: f5pools
- name: Display Config for a specific pool using a variable
debug:
var: item
loop: "{{ f5pools | json_query(pool_name) }}"
vars:
pool_name: "ltm_pools[?name=='{{ poolName }}'].{name: name, Method: lb_method, Members: members[*].{name: name, state:real_state }, Monitors: monitors}"
You could modify it for just the names using:
- hosts: localhost
tasks:
- name: collect device info
bigip_device_info:
gather_subset:
- ltm-pools
delegate_to: localhost
register: f5pools
- name: Display Config for a specific pool using a variable
debug:
var: item
loop: "{{ f5pools | json_query(pool_name) }}"
vars:
pool_name: "ltm_pools[?name=='{{ poolName }}'].members[*].name"
Which worked see output:
{
"ansible_loop_var": "item",
"_ansible_no_log": false,
"item": [
"1.1.1.2:443",
"1.1.1.3:443"
],
"changed": false,
"_ansible_verbose_always": true,
"_ansible_item_label": [
"1.1.1.2:443",
"1.1.1.3:443"
]
}

Related

WordPress / WooCommerce update statement blocks entire MariaDB database on WP Multisite setup

I have a wordpress/woocommerce stack with a couple of plugins activated, once or twice a day MariaDB database (AWS RDS MariaDB 10.6) hangs and becomes completely unreachable to the point where I need to reboot the instance.
The error log shows too many connections errors and the connections indeed reach their max_connections value. I set up slow query logging to examine what happens when this occurs.
When the problem occured again, indeed the slow query log got written to the point where the RDS instance hanged again and needed a reboot.
It seems to be an update statement :
https://aws.amazon.com/rds/). started with:
Tcp port: 3306 Unix socket: /tmp/mysql.sock
Time Id Command Argument
# Time: 221108 14:00:54
# User#Host: wordpress[wordpress] # [10.0.0.191]
# Thread_id: 151359 Schema: wp_multisite_002 QC_hit: No
# Query_time: 50.027958 Lock_time: 0.050058 Rows_sent: 0 Rows_examined: 0
# Rows_affected: 0 Bytes_sent: 67
use wp_multisite_002;
SET timestamp=1667916054;
UPDATE `wp_2_options` SET `option_value` = '1668002404' WHERE `option_name` = '_transient_timeout_et_core_path';
# User#Host: wordpress[wordpress] # [10.0.0.191]
# Thread_id: 151362 Schema: wp_multisite_002 QC_hit: No
# Query_time: 50.053338 Lock_time: 0.050050 Rows_sent: 0 Rows_examined: 0
# Rows_affected: 0 Bytes_sent: 67
SET timestamp=1667916054;
UPDATE `wp_2_options` SET `option_value` = '1668002404' WHERE `option_name` = '_transient_timeout_et_core_path';
# Time: 221108 14:00:55
# User#Host: wordpress[wordpress] # [10.0.0.191]
# Thread_id: 151364 Schema: wp_multisite_002 QC_hit: No
# Query_time: 50.047369 Lock_time: 0.050090 Rows_sent: 0 Rows_examined: 0
# Rows_affected: 0 Bytes_sent: 67
SET timestamp=1667916055;
UPDATE `wp_2_options` SET `option_value` = '1668002405' WHERE `option_name` = '_transient_timeout_et_core_path';
# Time: 221108 14:00:58
# User#Host: wordpress[wordpress] # [10.0.0.191]
# Thread_id: 151371 Schema: wp_multisite_002 QC_hit: No
# Query_time: 50.001565 Lock_time: 0.050071 Rows_sent: 0 Rows_examined: 0
# Rows_affected: 0 Bytes_sent: 67
SET timestamp=1667916058;
Is there anyone who knows what could cause this and what's the use of this statement , google search on _transient_timeout_et_core_path doesn't give me much information.
I can't replicate the problem because I don't know what's the reason it occurs.
It does happen everyday, once or twice, also no excessive amounts of users , mostly 1 or 2 at the same time and I'm not even sure if anyone is actively using the site when it happens.
Thanks

Attaching a new volume each time a node group is scaled

Can anyone share any reference template to create a new volume and attach to a new instance each time a deployment for that instance is scaled up?
My template looks like:
node_templates:
key_pair:
...
vol:
...
node_host:
...
relationships:
...
- key_pair
- vol
node:
...
relationships:
- type: cloudify.relationships.contained_in
target: node_host
...
groups:
scale_up_group:
members: [node, node_host, vol]
policies:
auto_scale_up:
type: scale_policy_type
properties:
policy_operates_on_group: true
scale_limit: 6
scale_direction: '<'
scale_threshold: 15
service_selector: cpu.total.user
cooldown_time: 60
triggers:
execute_scale_workflow:
type: cloudify.policies.triggers.execute_workflow
parameters:
workflow: scale
workflow_parameters:
delta: 1
scalable_entity_name: node
scale_compute: true
Courtesy of Trammell from cloudify-user group:
node_templates:
key_pair:
type: cloudify.openstack.nodes.KeyPair
...
floating_ip:
type: cloudify.openstack.nodes.FloatingIP
...
vol:
type: cloudify.openstack.nodes.Volume
...
node_host:
type: cloudify.openstack.nodes.Server
...
relationships:
- type: cloudify.openstack.server_connected_to_keypair
target: keypair
- type: cloudify.openstack.server_connected_to_floating_ip
target: floating_ip
- type: cloudify.relationships.depends_on
target: vol
node:
type: custom.node.type
...
relationships:
- type: cloudify.relationships.contained_in
target: node_host
...
groups:
scale_vm:
members: [node, node_host, floating_ip, vol]
scale_up_group:
members: [node, node_host, floating_ip, vol]
policies:
auto_scale_up:
type: scale_policy_type
properties:
policy_operates_on_group: true
scale_limit: 6
scale_direction: '<'
scale_threshold: 15
service_selector: cpu.total.user
cooldown_time: 60
triggers:
execute_scale_workflow:
type: cloudify.policies.triggers.execute_workflow
parameters:
workflow: scale
workflow_parameters:
delta: 1
scalable_entity_name: scale_vm
scale_compute: true
policies:
scale_vm_policy:
type: cloudify.policies.scaling
properties:
default_instances: 1
targets: [scale_vm]
Ref: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/cloudify-users/TPepGofpSBU

Can't select JCheckBoxMenuItem, components in context not recognized

I've started working in robot framework's swing library, gui testing a java application in swing.
I have to select the jcheckboxmenuitem "waveMenu" from a jpopupmenu "menu" on a jtextarea "showText". Running the keyword:
Select From Popup Menu showText menu|waveMenu
Results in a very unhelpful error.
Fail: Popup menu
If I try to right click on the component showText, it simply passes without bringing up the menu associated with it. The menu is attached by a regular mouselistener.
showText.addMouseListener(new MouseAdapter() {
#Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
});
Listing components in context from the top results in this
Level: 0 Component: ca.acme.myApplication
Index: 0 Name: the name I select when I run Select Window
Level: 1 Component: javax.swing.JRootPane Index: 0 Name: null
Level: 2 Component: javax.swing.JPanel Index: 0 Name: null.glassPane
Level: 2 Component: javax.swing.JLayeredPane Index: 0 Name: null.layeredPane
Level: 3 Component: javax.swing.JPanel Index: 1 Name: null.contentPane
Level: 4 Component: javax.swing.JPanel Index: 2 Name: null
Level: 5 Component: javax.swing.JButton Index: 0 Name: fileOpenButton
Level: 5 Component: javax.swing.JTextField Index: 0 Name: fileText
Level: 5 Component: javax.swing.JButton Index: 1 Name: fileSendButton
Level: 5 Component: javax.swing.JLabel Index: 0 Name: null
Level: 5 Component: javax.swing.JTextField Index: 1 Name: hostText
Level: 5 Component: javax.swing.JComboBox Index: 0 Name: formatSelect
Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 2 Name: null
Level: 6 Component: javax.swing.CellRendererPane Index: 0 Name: null
Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 1 Name: null
Level: 5 Component: javax.swing.JComboBox Index: 1 Name: voiceSelect
Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 3 Name: null
Level: 6 Component: javax.swing.CellRendererPane Index: 1 Name: null
Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 2 Name: null
Level: 5 Component: javax.swing.JComboBox Index: 2 Name: delaySelect
Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 4 Name: null
Level: 6 Component: javax.swing.CellRendererPane Index: 2 Name: null
Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 3 Name: null
Level: 5 Component: javax.swing.JTextField Index: 2 Name: messageText
Level: 5 Component: javax.swing.JButton Index: 5 Name: messageSendButton
Level: 5 Component: javax.swing.JLabel Index: 4 Name: portLabel
Level: 5 Component: javax.swing.JTextField Index: 3 Name: portText
Level: 5 Component: javax.swing.JComboBox Index: 3 Name: requestSelect
Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 6 Name: null
Level: 6 Component: javax.swing.CellRendererPane Index: 3 Name: null
Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 5 Name: null
Level: 5 Component: javax.swing.JComboBox Index: 4 Name: speedSelect
Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 7 Name: null
Level: 6 Component: javax.swing.CellRendererPane Index: 4 Name: null
Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 6 Name: null
Level: 5 Component: javax.swing.JComboBox Index: 5 Name: siteSelect
Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 8 Name: null
Level: 6 Component: javax.swing.CellRendererPane Index: 5 Name: null
Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 7 Name: null
Level: 5 Component: javax.swing.JScrollPane Index: 0 Name: null
Level: 6 Component: javax.swing.JViewport Index: 0 Name: null
Level: 7 Component: javax.swing.JTextArea Index: 4 Name: showText
Level: 6 Component: javax.swing.JScrollPane$ScrollBar Index: 0 Name: null
Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 9 Name: null
Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 10 Name: null
Level: 6 Component: javax.swing.JScrollPane$ScrollBar Index: 1 Name: null
Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 11 Name: null
Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 12 Name: null
Going down a level and attempting even the most basic interactions with the application results in failure
I don't mind providing more detail if needed. I've been stuck on this problem for ages.
I've found the issue.
if (e.isPopupTrigger()) {
menu.show(e.getComponent(), e.getX(), e.getY());
}
Javadoc:
Returns whether or not this mouse event is the popup menu trigger event for the platform.
I think the windows popup menu trigger is different from the one that the robot framework swing library sends. Right clicking on the component passed and did nothing because it did, in fact, pass; it just got negated by the if statement.

orientdb SEVER Error during extraction: java.lang.IllegalArgumentException: Field name is empty

I have this file that I'm trying to import on orientdb it has the following structure :
p1 p2 combined_score
1 568703.LGG_00001 568703.LGG_01682 282
2 568703.LGG_00001 568703.LGG_01831 183
3 568703.LGG_00001 568703.LGG_01491 238
I'm doing the import using oetl :
{
"source": { "file": { "path": "C:/Users/Desktop/files/file22/lac2.csv" } },
"extractor": { "csv": {} },
"transformers": [
{ "vertex": { "class": "nodes" } }
],
"loader": {
"orientdb": {
"dbURL": "plocal:/tmp/databases/db/db",
"dbType": "graph",
"classes": [
{"name": "nodes", "extends": "V"},
]
}
}
}
Trying to import the vertices first and then the nodes .
Yet I'm getting this error
2017-06-26 18:38:27:059 SEVER Error during extraction: java.lang.IllegalArgumentException: Field name is empty [OETLProcessor$OETLExtractorWorker]+ extracted 0 rows (0 rows/sec) - 0 rows -> loaded 0 vertices (0 vertices/sec) Total time: 2012ms [0 warnings, 0 errors]
+ extracted 0 rows (0 rows/sec) - 0 rows -> loaded 0 vertices (0 vertices/sec) Total time: 3033ms [0 warnings, 0 errors]
+ extracted 0 rows (0 rows/sec) - 0 rows -> loaded 0 vertices (0 vertices/sec) Total time: 4033ms [0 warnings, 0 errors]
Nothing is loading ,How can I solve this ?
I'm using orientdb community-2.2.18 and tried 2.2.22 vrsion too and the problem is percisting
This message:
2017-06-26 18:38:27:059 SEVER Error during extraction: java.lang.IllegalArgumentException: Field name is empty
is because in your csv file, the name of the property in blank, you can modify your csv file in this way without giving it a name:
p1,p2,combined_score
1,568703.LGG_00001,568703.LGG_01682,282
2,568703.LGG_00001,568703.LGG_01831,183
3,568703.LGG_00001,568703.LGG_01491,238
and this will be your output:
+----+-----+------+----+----------------+----------------+
|# |#RID |#CLASS|p1 |combined_score |p2 |
+----+-----+------+----+----------------+----------------+
|0 |#17:0|nodes |1 |568703.LGG_01682|568703.LGG_00001|
|1 |#18:0|nodes |2 |568703.LGG_01831|568703.LGG_00001|
|2 |#19:0|nodes |3 |568703.LGG_01491|568703.LGG_00001|
+----+-----+------+----+----------------+----------------+
otherwise, if you wanna give it a name, do it in this way:
id,p1,p2,combined_score
1,568703.LGG_00001,568703.LGG_01682,282
2,568703.LGG_00001,568703.LGG_01831,183
3,568703.LGG_00001,568703.LGG_01491,238
and this will be the output:
+----+-----+------+----------------+--------------+----------------+----+
|# |#RID |#CLASS|p1 |combined_score|p2 |id |
+----+-----+------+----------------+--------------+----------------+----+
|0 |#17:0|nodes |568703.LGG_00001|282 |568703.LGG_01682|1 |
|1 |#18:0|nodes |568703.LGG_00001|183 |568703.LGG_01831|2 |
|2 |#19:0|nodes |568703.LGG_00001|238 |568703.LGG_01491|3 |
+----+-----+------+----------------+--------------+----------------+----+
I tried with 2.2.22.
Hope it helps.
Regards

Ansible - math operation, substract

Trying to substract a number for a variable, which is an int in Ansible.
var:
number: 30
tasks:
- set_fact: me={{ number -1 }}
- debug: var=me
Expectation: me = 29
Result:
fatal: [node1]: FAILED! => {"failed": true, "msg": "Unexpected templating type error occurred on ({{ number - 1 }}): unsupported operand type(s) for -: 'AnsibleUnicode' and 'int'"}
It is a known issue with Ansible/Jinja that you can't preserve numeric type after templating.
Use int filter inside {{..}} expression:
- set_fact: me={{ number | int - 1 }}

Resources