Day 85 of DevOps, Day 35 of Azure. Both tasks today reported a state that is a word rather than a fact.
An Ansible playbook reported changed=1, and it would have reported that on every run for the rest of time, whether or not anything was different. And an Azure peering that was created reported a state, and moved no packets at all, because a peering is two resources and I had made one.
One Ansible task, one Azure task. Write a playbook that creates a file, then peers two virtual networks. The tasks come from the KodeKloud Engineer platform.
Task 1: A playbook that creates a file
The task: a playbook that creates an empty /tmp/file.txt on App Server 01.
Step 1: Look before you run
[tony@stapp01 ~]$ ls /tmp
systemd-private-... (no file.txt)
This is the step that makes the result mean something, and the next section is why. A file that was already there would produce an identical task result, so the before-check is the only thing that distinguishes creating a file from doing nothing to one.
Step 2: The playbook
---
- hosts: app_server
become: yes
tasks:
- name: Create empty file
file:
path: /tmp/file.txt
state: touch
TASK [Create empty file] *************** changed: [stapp01]
PLAY RECAP *************** stapp01 : ok=2 changed=1 unreachable=0 failed=0
Then after, ls shows the file and cat shows nothing, which is the check for "empty" and worth actually running. touch creates an empty file; a copy or lineinfile task would not.
Step 3: That task will report a change forever
Yesterday's playbook installed a package and started a service, and a second run reports changed=0. Both modules describe a desired state, and a system already in that state needs no action. That is the property Ansible is usually sold on.
This playbook does not have it, and the reason is a default that applies to exactly one state.
access_time and modification_time default to None,"meaning that preserve is the default for state=[file,directory,link,hard]" while "now is default for state=touch."
So every run sets both timestamps to the current time. That is a real change to the filesystem, and Ansible correctly reports it as one. The file's existence is idempotent. Its mtime is not.
The documentation gives the fix as an example rather than a statement, in a snippet labelled "Touch again the same file, but do not change times this makes the task idempotent":
- name: Create empty file, idempotently
ansible.builtin.file:
path: /tmp/file.txt
state: touch
modification_time: preserve
access_time: preserve
Worth more than tidiness. The changed count in a recap is the signal that something moved, and it only works if tasks that change nothing say so. One bare state: touch makes every run of that playbook report a change for the rest of its life. On a playbook with forty tasks, that is the difference between a recap you read and a recap you scroll past.
The requirement was to create the file, so the version I wrote satisfies it. The version above satisfies it and is still honest on the second run.
What the docs recommend
Two other things in those few lines, and the first is the third time this decision has come up in this series.
stapp01 ansible_user=tony ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Ansible documents both the behaviour and its own switch for it: "Ansible enables host key checking by default", because "Checking host keys guards against server spoofing and man-in-the-middle attacks". To turn it off, the documented route is host_key_checking = False in ansible.cfg or the ANSIBLE_HOST_KEY_CHECKING variable. StrictHostKeyChecking appears nowhere in Ansible's documentation; it is the ssh client's own option, passed through.
The inventory version is arguably the better of the two, because of scope. The config setting disables verification for every host Ansible touches. The inventory variable disables it for stapp01 only.
But it was not needed at all. My own transcript shows ssh-copy-id and then an interactive ssh answering yes to the authenticity prompt, which writes the key into known_hosts. Verification would have succeeded. The flag is insurance against a host key that is already known.
And it is the same choice I made in Jenkins on Day 75, where the agent's host key strategy was set to Non verifying, and the plugin's page carries the advisory that setting re-opens: "Man-in-the-middle vulnerability due to missing host key verification". Three tools, three syntaxes, one decision, and the attack it protects against is the same every time.
The second thing is quieter. become: yes means root creates the file, so the file is root-owned. The module's owner default explains why nothing else was possible: unspecified, "it uses the current user unless you are root, in which case it can preserve the previous ownership", and a file that did not exist has no previous ownership. Fine here, not usually what you want, and two lines to fix. Day 86's playbook sets it explicitly, so the pair makes the comparison on its own.
Task 2: Two virtual networks
The task: peer a public VNet to a private one and prove a VM in each can talk.
Step 1: I made one and it did nothing
xfusion-pub-to-priv-peering State: Initiated
ping 10.1.1.4 -> 4 packets transmitted, 0 received, 100% packet loss
Azure peering is a pair of child resources, one on each VNet, each describing its own direction. A single half sits in Initiated, which means the offer has been made and the other side has not agreed, and nothing routes.
Creating the reverse flipped both to Connected, and the ping went to 4 of 4.
| AWS | Azure | |
|---|---|---|
| Resources | One connection, pcx-...
|
Two peerings, one per VNet |
| Pending state | pending-acceptance |
Initiated |
| Completing it | accept-vpc-peering-connection |
Create the reverse peering |
| Working state | active |
Connected on both |
Different shapes, identical trap: a half-built peering looks like a resource that exists. Day 49's accept step and today's second create are the same lesson, that the thing you created is not the thing that works.
And there is a third way for this to look finished and not be. --allow-vnet-access is what actually permits traffic, and a peering can read Connected with it set to false, which is a connected peering that forwards nothing.
Step 2: Azure wrote the routes for me
az network nic show-effective-route-table --ids $PUB_NIC_ID -o table | grep -i peering
Default Active 10.1.0.0/16 VNetPeering
Source Default, meaning Azure created it. The moment both halves reached Connected, a system route for the peer's address space appeared on every NIC in the VNet.
Day 49 required this by hand, in both route tables, and that note called out the failure mode of doing only one: packets arrive and replies cannot get home. On Azure that mode does not exist, because the routes are a consequence of the peering rather than a separate thing to remember.
The flip side is that a user-defined route can still override an injected one, which is the Day 28 fault pattern exactly. show-effective-route-table stays the way to see what actually applies.
Step 3: No NSG change at all, and that is the part to be careful about
Both NSGs had exactly one rule, SSH on port 22. Nothing permitting ICMP, nothing mentioning the peer's address space, and ping worked.
The reason is the VirtualNetwork service tag, which the default rule AllowVnetInBound at priority 65000 permits all protocols from. My notes listed three things that tag covers. The documented list has six:
"The virtual network address space (all IP address ranges defined for the virtual network), all connected on-premises address spaces, peered virtual networks, virtual networks connected to a virtual network gateway, the virtual IP address of the host, and address prefixes used on user-defined routes."
Two of those I had missed, and both are worth having.
"The virtual IP address of the host" is 168.63.129.16, yesterday's platform address. So the same tag that admits peered traffic also admits the platform channel, which is part of why that address is so hard to cut off.
"Address prefixes used on user-defined routes" is the one that changed how I think about this. Adding a route widens the tag.
So the set of sources AllowVnetInBound admits grows when you peer a VNet, when you attach a gateway, and when you write a route. None of those are NSG changes. None of them appear anywhere in the NSG.
Which makes the convenience and the hazard the same fact. Peering plus nothing else gave me working connectivity between two VMs. And an NSG audited as "only allows internal traffic" means something different afterwards, with no record in the NSG that anything happened.
Day 49 needed an explicit security group rule for precisely this, because an AWS security group has no concept corresponding to "my VPC plus its peers". Day 49's list of peering requirements was four items. On Azure it is two: non-overlapping CIDRs, and both halves created.
What the docs recommend
The best thing about this task was an accident.
I ran the ping before creating the reverse peering, which was not the plan, and it gave a real baseline:
before: 4 packets transmitted, 0 received, 100% packet loss
after: 4 packets transmitted, 4 received, 0% packet loss
A successful ping proves connectivity. A successful ping that failed completely from the identical command ten minutes earlier proves the peering caused it. That is the Day 19 and Day 40 pattern, establish the negative first, arrived at by luck rather than discipline.
It is also the same thing the Ansible half did deliberately, with ls -la /opt/data on each server first. One planned, one accidental, and both are the reason either result means anything.
Worth noting too that the Initiated state and the 100% packet loss agreed with each other. Configuration and behaviour pointed at the same gap, which is what makes a diagnosis solid rather than a guess, and is the opposite of Day 28 where a working site rested on wrong configuration.
Two constraints that do carry over from AWS. Overlapping address space blocks peering on both platforms with no translation option, which is why Day 5 flagged that "any CIDR" is only safe in isolation. And peering is not transitive on either, so a third VNet peered with the public one would have no path to the private one. Past three or four VNets the answer is hub-and-spoke.
What I learned
Both halves reported a state that is a word rather than a fact.
changed=1 looks like "the file was created". It means "the filesystem is different from before", and with state: touch it will say that forever, because the default is to update the timestamps every run. The fix is two lines and it is in the documentation as an example rather than a warning, so you only find it if you go looking for why your recap never settles.
The Azure peering is the sharper version. I created it, it reported a state, the state was a word rather than an error, and nothing moved. Three separate ways for that to happen: one half instead of two, both halves with --allow-vnet-access false, or a user-defined route overriding the one Azure injects. In all three, the peering exists and reads as configured.
The finding I would actually use is the service tag. Peering a network, attaching a gateway, or writing a route each silently widen what every NSG rule written against VirtualNetwork permits, on both sides, with no change to the NSG and nothing in it to show what happened. An NSG review that only reads NSGs is not a complete review.
So here is the Day 85 question. Which number on your dashboard would read exactly the same if the thing it measures had stopped changing a month ago?
Day 85 down. Fifteen to go.
Top comments (0)