My YAML file for the handler is as below: Yaml file location is as below
ansible_patching/ssm_agent.yml
---
- hosts: all
gather_facts: true
become: true
roles:
- ssm_agent
roles/ssm_agent/handlers/main.yml
# handlers file for ansible-role-ssm-agent
- name: systemctl_handler
systemd:
name: amazon-ssm-agent
daemon_reload: yes
state: "{{ ssm_agent_svc_state }}"
enabled: yes
ansible_patching/roles/ssm_agent/tasks/main.yml
---
- name: Check required input parameters
assert:
that:
- ({{ item }} is defined)
- ({{ item }} is not none)
- ({{ item }} | trim != '')
with_items:
- os_name
- os_version
loop_control:
loop_var: item
- name: Include architecture specific
include: "{{ ansible_architecture }}.yml"
- name: Include for centos 7
include: install_{{ os_name }}_{{ os_version }}.yml
when: ansible_distribution == "{{ os_name }}" and ansible_distribution_major_version == "{{ os_version }}"
The error I get is as below
RUNNING HANDLER [ansible_role_ssm_agent : systemctl_handler] ********************************************************
fatal: [13.236.87.146]: FAILED! => {"changed": false, "msg": "failure 1 during daemon-reload: Failed to execute operation: Connection timed out\n"}
However, I can restart service with the same remote user(ansible) on the remote host [ Public IP of Remote CentOS Host ]
Please find below output:
[ansible@ip-172-31-33-3 tmp]$ sudo systemctl status amazon-ssm-agent
[sudo] password for ansible:
● amazon-ssm-agent.service - amazon-ssm-agent
Loaded: loaded (/etc/systemd/system/amazon-ssm-agent.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-06-25 01:22:40 UTC; 44min ago
Main PID: 1978 (amazon-ssm-agen)
CGroup: /system.slice/amazon-ssm-agent.service
└─1978 /usr/bin/amazon-ssm-agent
[ansible@ip-172-31-33-3 tmp]$ sudo systemctl restart amazon-ssm-agent
[ansible@ip-172-31-33-3 tmp]$ sudo systemctl status amazon-ssm-agent
● amazon-ssm-agent.service - amazon-ssm-agent
Loaded: loaded (/etc/systemd/system/amazon-ssm-agent.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-06-25 02:07:06 UTC; 2s ago
Main PID: 2157 (amazon-ssm-agen)
CGroup: /system.slice/amazon-ssm-agent.service
└─2157 /usr/bin/amazon-ssm-agent
Note: The playbook (ansible ssm agent installation role) does work fine if I comment daemon_reload: yes
Any guidance shall be appreciated.
[ansible@ip-172-31-38-88 ~]$ sudo systemctl daemon-reload
[ansible@ip-172-31-38-88 ~]$ echo $?
0
Edit 2: Works fine on the remote host with sudo command
[ansible@ip-172-31-38-88 ~]$ sudo cat /etc/sudoers |grep ansible
[sudo] password for ansible:
ansible ALL=(ALL) ALL
[ansible@ip-172-31-38-88 ~]$
Edit 4: Remote ansible user has identical permissions like root user.
daemon-reload
attribute? This should executesystemctl daemon-reload
on the remote machine. Can you successful execute it as the ansible user? – yabberthsudo
. Is this possible?sudo systemctl daemon-reload
– yabberth