Hi everyone,
I’m still a bit new to Ansible. I really like it, but it can be a little flummoxing at times for a beginner ;).
For example, I am probably going about this the wrong way, but consider these lines from a playbook:
`
- name: Configure MTA to Local Only – CIS 3.16
lineinfile: dest=/etc/postfix/main.cf
regexp=‘^(?i)inet_interfaces.*’
line=‘inet_interfaces = localhost’
state=present
`
This produces the following output:
TASK: [cis | Configure MTA to Local Only -- CIS 3.16] ************************* failed: [devct67.umaryland.edu] => {"failed": true, "item": "", "rc": 257} msg: Destination /etc/postfix/main.cf does not exist !
OK. So, not all of my machines have postfix on them. But if they do, I want to run this ‘lineinfile’ command.
I have considered almost every “when” option I can think of, but most of them fail because it’s a negative test. For example, I wrote a plugin that returns all packages on a system in a dictionary. So I had a line like:
when: "packages['postfix'] == True"
produces:
TASK: [cis | Configure MTA to Local Only -- CIS 3.16] ************************* fatal: [devct67.umaryland.edu] => error while evaluating conditional: umb_packages['postfix'] == True
That fails, however, when postfix isn’t installed, which is exactly what I’m trying to find out.
So- what are my options? How should I be doing this?