Creating a Bamboo Agent wit Ansible
Asked by William Flow:

Hi all

so I have an Ansible Playbook that:

1. Creates and Ubuntu EC2 on AWS

2. Then updates the EC2 and installs some packages and reboots

3. It then creates a Bamboo user and group and sets the password

4. It copies the Bamboo agent tar file sets its owner as Bamboo

5. I then run the installer and it approves the new agent via an API call

6. The script waits until the file bamboo-agent.cfg.xml is created

The problem is sometimes it happens meaning everything goes well and my new agent goes live on line or it just sits there then times out, I look at the logs and see that it is waiting to get approval   

INFO \| jvm 2 \| 2022/09/25 20:09:02 \| \* This agent requires manual approval.  
INFO \| jvm 2 \| 2022/09/25 20:09:02 \| \* UUID: xxxxxxxxxxxxxxxxxxxxxxxxxx

then I look at the Bamboo agents  

|-----------|-----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| x.x.x.227 | xxxxxxxxx | Waiting | [Approve access](https://cicd.devops.kratosdefense.com/admin/agent/configureAgentAuthentications!approve.action?authenticationUuid=d480e8fa-eaa6-40ee-9866-8c0b40ff1f77) |

|-----------|--------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| x.x.x.227 | xxxxxx | Approved | [Revoke access](https://cicd.devops.kratosdefense.com/admin/agent/configureAgentAuthentications!revokeApproval.action?authenticationUuid=d82e4c0a-f329-4803-9900-fb9002790a67)\| [Edit IP address](https://cicd.devops.kratosdefense.com/admin/agent/editAgentAuthenticationIp.action?authenticationUuid=d82e4c0a-f329-4803-9900-fb9002790a67) |

so how can it be approved and still asking for approval? I need this to be able to setup and start the agent without errors, any help would be great


Answers:
author: Eduardo Alvarenga
body: Hello [@William Flow](/t5/user/viewprofilepage/user-id/4551025),

The Bamboo Agent jar installer will keep trying to connect to the Bamboo Server every 60s in case it is not approved. Perhaps you need to wait longer and double-check the UUID inserted on **bamboo.cfg.xml** and use it on the REST API agent approval request.

Alternatively, you can install the Agent using the ***install*** suffix, this will only create the necessary content but will not run any services. You can then generate a **bamboo.cfg.xml**from a template and assign it with a random UUID then start the Agent. This way you have control of the UUID and will be 100% sure of which agent needs to be approved.

* [Additional remote agent options - Running the remote agent with different start-up commands](https://confluence.atlassian.com/bamboo/additional-remote-agent-options-436044733.html)

Cheers,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: William Flow
body: Hi Eduardo so what I am thinking is

1. install the jar file via command:

sudo runuser -l bamboo -c 'java -Dbamboo.home=/home/bamboo -jar /home/bamboo/atlassian-bamboo-agent-installer-8.0.9.jar <https://cicd.system/agentServer/>'  
2. it waits for the  
uuid-temp.properties file and garbs the UUID  
3. They I approve the agent:  
<https://mybamboo.com/rest/api/latest/agent/authentication/>{{ bamboo_agent_uuid }}  
4. wait for the bamboo-agent.cfg.xml file  
How long should I wait for step 4 ?  
or should i do a  
sudo runuser -l bamboo -c 'java -Dbamboo.home=/home/bamboo -jar /home/bamboo/atlassian-bamboo-agent-installer-8.0.9.jar <https://cicd.system/agentServer/>  
install' then do the the approve then start the agent with a sudo runuser -l bamboo -c '/home/bamboo/bin/bamboo-agent.sh start' then wait for the bamboo-agent.cfg.xml file?  
which do you think is better and how long to wait?  
Thanks for your help


author: Eduardo Alvarenga
body: Hello [@William Flow](/t5/user/viewprofilepage/user-id/4551025)

The wait times will depend on external factors that are out of Bamboo's control as it relies on your automation.

I'd go with the second option where you have better control of the installation process.

1. Use the *install* option
2. Place a "skeleton" **bamboo-agent.cfg.xml** with the minimal configuration:

   ```
   <?xml version="1.0" encoding="UTF-8" standalone="no"?>
   <configuration>
       <buildWorkingDirectory>/home/bamboo/bamboo-agent-home/xml-data/build-dir</buildWorkingDirectory>
       <agentUuid>YOU27c1a-NEED-4ebc-_TO_-af8bGENERATE</agentUuid>
       <agentDefinition>
           <name>agent_NAME</name>
           <description>Remote agent on host agent_NAME</description>
   </agentDefinition>
   </configuration>
   ```

3. Start the Agent
4. Approve it via the API
5. The agent will restart every 60s and will connect to the Server once approved and add the remaining information to **bamboo-agent.cfg.xml**.

Regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: William Flow
body: Ok will do one more question once I install it, then start it (via API), it will take time in communicating from my new agent to the bamboo server, example it will poll every minute until it sees that I approved it? So by setting my poll to check for the bamboo-  
-agent.cfg.xml is there every 10 seconds for 10 minutes that in general should be enough time?


author: Eduardo Alvarenga
body: Hello [@William Flow](/t5/user/viewprofilepage/user-id/4551025)

The Bambo Agent will wait up to 60s and try again when in the Approval stage.

During the first start, the Agent will download extra files from the server, so you can add 2 or 3 minutes as a grace period (It may be more or less depending on your Network speed).

After that, capture the UUID from the **bamboo-agent.cfg.xml** (or use the one you have generated as per my previous suggestion) and approve it on the API.

Once the Agent is approved it will try again and succeed with the connection to the Server.

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: William Flow
body: Hi [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) I found my issue, what happens is   

1. i do the install with the install flag

2. I start the agent and do some more stuff

3. I restart the agent and sometimes it works fine other times I see the agent needs approval, i think the reason for this is I see the one that has already approved has and address of "the IP of the load balancer, the IP of the agent" like 10.xxx.xxx.61,10.xxx.xxx.221 and the one that is waiting is 10.xxx.xxx.91,10.xxx.xxx.221 which i think is causing the issue


author: Eduardo Alvarenga
body: Hello [@William Flow](/t5/user/viewprofilepage/user-id/4551025)

Good to hear from you!

Try this KB article to mask your LB IP addresses from the connection and focus on the Agent's IPs:

* [How to remove load balancer IP address from Bamboo agent authentication and approval](https://confluence.atlassian.com/bamkb/how-to-remove-load-balancer-ip-address-from-bamboo-agent-authentication-and-approval-968661004.html)

Regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: William Flow
body: Thanks for all your help [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410)