Skip to content

Uninstall or re-apply CodeDeploy agent on Ubuntu 20.04

0

A CodeDeploy deployment started failing today on an Ubuntu 20.04 EC2, so I investigated the issue and found code deploy was not running or even available as a service. Running service codedeploy-agent status and systemctl status codedeploy-agent told me there was no such service.

I have a Systems Manager 'AWS-ConfigureAWSPackage' association for this EC2 that has action 'Install' for name 'AWSCodeDeployAgent'.

After re-applying this association, I got AWSCodeDeployAgent 1.7.0 is already installed so I've tried to remove the code deploy agent manually:

sudo dpkg --purge codedeploy-agent
sudo service codedeploy-agent stop
sudo apt-get remove codedeploy-agent -y
sudo rm -rf /opt/codedeploy-agent
sudo rm -rf /etc/codedeploy-agent

After re-applying this association again, I still get AWSCodeDeployAgent 1.7.0 is already installed. How do I completely remove code deploy from this EC2 so I can re-run the association and have a clean install?

3 Answers
1
Accepted Answer

I have managed to fix this by opening up the 'successful' Association command, using Copy to new and setting the optional Version parameter to 1.3.2. This showed errors trying to uninstall 1.7.0, but then continued and successfully installed 1.3.2. I've now run a successful deploy.

answered a year ago
EXPERT
reviewed a year ago
1

Hello.

I think it can be deleted using the following command.
https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-uninstall.html

sudo dpkg --purge codedeploy-agent
EXPERT
answered a year ago
EXPERT
reviewed a year ago
  • Sorry I forgot to include that I had already run that command as well

  • Is it still not possible to delete it even if I select uninstall in "Action" as shown below? I tried it in my environment and was able to remove it from Systems Manager and reinstall it as shown in the image below. a

    By the way, you may also try running the following command.

    sudo systemctl daemon-reload
    
0

Hello,

To completely remove the CodeDeploy agent and ensure a clean reinstall, try the following steps:

  1. Purge the package:
sudo dpkg --purge codedeploy-agent

Remove remaining files:

sudo rm -rf /opt/codedeploy-agent /etc/codedeploy-agent /var/codedeploy-agent

Clean apt cache:

sudo apt-get clean

Re-run the Systems Manager association:

EXPERT
answered a year ago
  • Hi Kranthi, I ran these commands, rebooted, but unfortunately, I still get 'AWSCodeDeployAgent 1.7.0 is already installed'. If I connect to the instance:

    root:/var/snap/amazon-ssm-agent/8254# systemctl status codedeploy-agent
    Unit codedeploy-agent.service could not be found.
    root:/var/snap/amazon-ssm-agent/8254# service codedeploy-agent status
    Unit codedeploy-agent.service could not be found.
    

    The previous agent was Version: 1.3.2-1902

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.