Initial run of Pluralith via Ansible
unix-bomber opened this issue · comments
Things aren't running as required right now - working through troubleshooting issues in this issue
Pluralith should be initialized manually at first in the project directory until the init command is worked out. After that, if Ansible is being ran by a non-root account, ensure that you chown Pluralith directories as required as the account that will be running Ansible.
This applies to the pluralith install as well without ansible.
IE
chown $USER ./*pluralith*
It appears there's an issue with quoting more complex dictionary values:
In the case of the variable & value
pluralith_terraform_variables:
public_cidr_block_allow_inbound: '["192.168.2.0/23", "192.168.12.0/23"]'
Yields the error
STDERR: Error: invalid argument "\"public_cidr_block_allow_inbound=[\"192.168.2.0/23\", \"192.168.12.0/23\"]\"" for "--var" flag: parse error on line 1, column 35: extraneous or missing " in quoted-field
Usage:
pluralith run [flags]
Flags:
--cost-mode string Determines which costs are shown. Can be 'delta' or 'total' (default "delta")
--cost-period string Determines over which period costs are aggregated. Can be 'hour' or 'month' (default "month")
--cost-usage-file string Path to an infracost usage file to be used for the cost breakdown
--export-pdf Determines whether a PDF export of the run Diagram is generated locally
--file-name string The name of the exported PDF
-h, --help help for run
--out-dir string The directory the diagram should be exported to
--show-changes Determines whether the exported diagram highlights changes made in the latest Terraform plan or outputs a general diagram of the infrastructure
--show-costs Determines whether the exported diagram includes cost information
--show-drift Determines whether the exported diagram highlights resource drift detected by Terraform
--title string The title for your diagram, will be displayed in the PDF output
--var strings A variable to pass to Terraform. Can be specified multiple times. (Format: --var='NAME=VALUE')
--var-file strings Path to a var file to pass to Terraform. Can be specified multiple times.
--version string The diagram version, will be displayed in the PDF output
Error: invalid argument "\"public_cidr_block_allow_inbound=[\"192.168.2.0/23\", \"192.168.12.0/23\"]\"" for "--var" flag: parse error on line 1, column 35: extraneous or missing " in quoted-field
However, when single quotes are removed as so
pluralith_terraform_variables:
public_cidr_block_allow_inbound: ["192.168.2.0/23", "192.168.12.0/23"]
The output message of the Pluralith module yields
"state": {
"pluralith_output": "⠿ Initiating Run ⇢ Posting To Pluralith Dashboard\n → Branch detected: dev\n\n→ Verify\n ✔ API key is valid, you are authenticated!\n ✔ Project ID is valid!\n\n→ Plan\n ✘ Couldn't Generate Execution Plan\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mInvalid character\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on <value for var.public_cidr_block_allow_inbound> line 1:\n\u001b[31m│\u001b[0m \u001b[0m (source code not available)\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mSingle quotes are not valid. Use double quotes (\") to enclose strings.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mInvalid expression\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on <value for var.public_cidr_block_allow_inbound> line 1:\n\u001b[31m│\u001b[0m \u001b[0m (source code not available)\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mExpected the start of an expression, but found an invalid expression token.
The Ansible terraform module requires a single quote around lists such as in the first example
Looks like issue may lay on line 178 in pluralith.py but may be deeper and lay with the --var flag in pluralith itself
executable += [f'--var="{key}={val}"' for key, val in tf_vars.items()] # Construct variable flags
Hi man, I looked into the quotes issue. There was something wrong with the way Pluralith parses string inputs and Python's string parsing in the Ansible module caused some downstream issues because of that. I attempted to fix up both.
If you could try the following and run it again that would be great!
- Please download the CLI alpha release with the fix: https://github.com/Pluralith/pluralith-cli/releases/tag/v0.1.13-alpha
- Also update the Pluralith Ansible module in your local setup again
Let me know how it goes!
Thanks!
Ran/ modified the following from the download/ install script to get the CLI setup
(Overcommunicating, for good practice sake)
# Download latest release binary
curl -L https://github.com/Pluralith/pluralith-cli/releases/download/v0.1.13-alpha/pluralith_cli_linux_amd64_v0.1.13-alpha --output /tmp/pluralith
# Make binary executable
chmod +x "/tmp/pluralith"
# Move to /usr/local/bin
if [ -x "$(command -v sudo)" ]; then
sudo mv "/tmp/pluralith" "/usr/local/bin/pluralith"
else
mv "/tmp/pluralith" "/usr/local/bin/pluralith"
fi
echo "Pluralith successfully installed"
Will run today and give a heads up 👍
*Updated, didn't have -L in curl
@unix-bomber Appreciate the debugging man!
Will update the install script. Looking forward to the feedback.
I don't think the install script needs to be updated, just posting what I did for documentation purposes 👍
To run as user, have to run
chown $USER <path_to_project>/*pluralith*
After init.
Getting the following output
"pluralith_output": "⠿ Initiating Run ⇢ Posting To Pluralith Dashboard\n → Branch detected: pluralith_testing\n\n→ Verify\n ✔ API key is valid, you are authenticated!\n ✔ Project ID is valid!\n\n→ Plan\n ✔ Execution Plan Generated\n ✔ Secrets Stripped\n - Cost Calculation Skipped\n\n→ Export\n ✘ Diagram Generation Failed\npluralith-cli-graphing graph\n\nRender graph and export PDF\n\nOptions:\n --help Show help [boolean]\n --version Show version number [boolean]\n\nError: ENOENT: no such file or directory, open '/home/timothy/Pluralith/credentials'\n at Object.openSync (node:fs:585:3)\n at Object.openSync (pkg/prelude/bootstrap.js:739:32)\n at Object.readFileSync (node:fs:453:35)\n at Object.readFileSync (pkg/prelude/bootstrap.js:1025:36)\n at /snapshot/pluralith-cli-graphing/dist/build/commands/Graph.js\n at Generator.next (<anonymous>)\n at /snapshot/pluralith-cli-graphing/dist/build/commands/Graph.js\n at new Promise (<anonymous>)\n at /snapshot/pluralith-cli-graphing/dist/build/commands/Graph.js\n at Graph (/snapshot/pluralith-cli-graphing/dist/build/commands/Graph.js) {\n errno: -2,\n syscall: 'open',\n code: 'ENOENT',\n path: '/home/timothy/Pluralith/credentials'\n}\n\ngenerating diagram failed -> RunGraph: running CLI command failed -> GenerateDiagram: exit status 1\n ✘ Posting Run To Pluralith Dashboard Failed\nreading cache from disk failed -> HandleCIRun: open /home/timothy/jarviss-infrastructure-deployment-aws/roles/deploy-rke2-essential-infrastructure/files/.pluralith/pluralith.cache.json: no such file or directory\n"
Looking into it
Update* I see the /home/timothy/Pluralith/credentials in /usr/local/bin/Pluralith/credentials - moving that over
sudo cp -r /usr/local/bin/Pluralith /home/$USER/
sudo chown -R $USER /home/$USER/Pluralith
Got something published to the dashboard 🎊
Here's the output of a success
"pluralith_output": "⠿ Initiating Run ⇢ Posting To Pluralith Dashboard\n → Branch detected: pluralith_testing\n\n→ Verify\n ✔ API key is valid, you are authenticated!\n ✔ Project ID is valid!\n\n→ Plan\n ✔ Execution Plan Generated\n ✔ Secrets Stripped\n - Cost Calculation Skipped\n\n→ Export\n ✔ Diagram Generated\n ✘ Posting Run To Pluralith Dashboard Failed\nposting run for PR comment failed -> HandleCIRun: request failed -> LogRun: &{400 Bad Request 400 HTTP/2.0 2 0 map[Access-Control-Allow-Origin:[*] Content-Length:[54] Content-Type:[application/json; charset=utf-8] Date:[Wed, 24 Aug 2022 02:57:47 GMT] Etag:[W/\"36-Sbx30uwj25sHt5XLThLAnENn3l8\"] Server:[Google Frontend] X-Cloud-Trace-Context:[de4c20834e9c42d95956e55a0f391a9a] X-Powered-By:[Express]] {0xc0000f4c00} 54 [] false false map[] 0xc00037b700 0xc0000fa6e0}\n"
This looks excellent for an alpha. I see some of the bugs, but these aren't too extreme, and software lives and dies by small quick iterations. I'm sure y'all will figure these out soon enough
- name: Run Pluralith
community.general.pluralith:
command: "run" # See all available commands at https://docs.pluralith.com/docs/category/cli-commands
api_key: "YOUR API KEY HERE"
project_id: "YOUR PROJECT ID HERE" # Sign up and create a project at https://app.pluralith.com
project_path: "YOUR PROJECT PATH HERE"
tf_vars: "{{ variable_dict }}"
tf_backend_config:
region: “us-west-1"
bucket: "test"
key: "ansible_test"
profile: "qa_env"
register: command_result
This is an updated example for the run command as well. By dropping pluralith.py into
/home/timothy/venv/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/pluralith.py
I was able to get the module to be found by ansible. The community.general. prefix is required in the playbook.
^ Documentation/ info for anyone using Pluralith in the future.
I think we can close this issue out & I can create a few other issues based off of the first successful initial run. Those issues would be purely for organization purposes - no pressure
Thanks for testing so thoroughly man!
We'll work all your feedback into the integration so we can streamline the whole thing. Shouldn't take more than actually running the Ansible module once everything is smoothened out!
Closing the issue, as per your request 👍